SQL>desc表名SQL>descs_emp脚本sql.txtsql.sql1.上传脚本2.运行脚本@绝对路径/文件名@文件名(关注语言环境)selectuserenv('lang')fromdual;USERENV('LANG')----------------USUSERENV('LANG')----------------ZHSdesc一张表NameNull?Type------------------------------------------------------------------ID员工idNOTNULLNUMBER(7)LAST_NAME姓NOTNULLVARCHAR2(25)FIRST_NAME名VARCHAR2(25)USERID员工描述VARCHAR2(8)START_DATE入职日期DATECOMMENTS备注VARCHAR2(255)MANAGER_ID领导的员工idNUMBER(7)TITLE职位VARCHAR2(25)DEPT_ID部门idNUMBER(7)SALARY月薪NUMBER(11,2)COMMISSION_PCT提成NUMBER(4,2)sql语句的分类:数据检索select数据操作insertdeleteupdate数据定义createdropalter事务控制commitrollbacksavepoint数据控制grantrevoke选择投影连接查询语句:Afrom子句1.查询出任意一个字段select字段名from表名;selectsalaryfroms_emp;2.查询多个字段(用逗号分割)selectfirst_name,salaryfroms_emp;3.*号可以替代所有的字段select*froms_emp;4.表头的原样显示----使用双引号selectfirst_name,salarysalfroms_emp;selectfirst_name,salary"sal"froms_emp;可以让别名中包含空格selectfirst_name,salary"emPsal"froms_emp;5.字段的数学运算求每个人的年薪selectsalary*12yearsalfroms_emp;换一种年薪计算方式考虑提成selectsalary*12*(1+commission_pct/100)yearsalfroms_emp;selectsalary*12*(1+commission_pct/100)yearsalfroms_emp;nvl空值处理函数nvl(值/字段,如果是空要得到的值)第一个参数是NULL就返回第二个参数如果第一个参数不是NULL返回第一个参数selectnvl(salary*12*(1+commission_pct/100),0)yearsalfroms_emp;//logicerror空值要尽早处理空值和任何值做运算都是NULLselectsalary*12*(1+nvl(commission_pct,0)/100)yearsalfroms_emp;6.想把姓名显示出来selectfirst_name,last_namefroms_emp;字符串连接||selectfirst_name||last_namefroms_emp;字符串的表达'hello''_'''''selectfirst_name||'_'||last_namefroms_emp;this'sselectfirst_name||''''||last_namefroms_emp;7.排重显示---distinctselectsalaryfroms_emp;selectdistinctsalaryfroms_emp;补充:联合排重selectdistinctsalary,idfroms_emp;clearscreen!clearB条件子句wherewhere字段表达式表达式找出工资大于1400的first_name,salaryselectfirst_name,salaryfroms_empwhere1=1;//全部显示selectfirst_name,salaryfroms_empwhere1=2;//无显示selectfirst_name,salaryfroms_empwheresalary>1400;where条件限制行的返回符合条件返回不符合过滤掉字段表达式中可以使用的比较运算符=一个等号判断相等找出first_name,manager_id是Carmen的工资selectfirst_name,salary,manager_idfroms_empwherefirst_name='Carmen';数字类型可以直接用等号判断相等字符串不要忘记单引号oraclesql大小写不敏感单字符串的值大小写敏感><<=>=!=<>^=betweenandnotbetweenandinnotinlikenotlikeisnullisnotnulloracle(sql)也提供了一些运算符字段betweenaandb表达一个闭区间[a,b]工资salary在[800,1400]selectfirst_name,salaryfroms_empwheresalarybetween800and1400;字段in(list)list用逗号隔开的一组值查询一下部门号在414250人first_name,salaryselectfirst_name,salary,dept_idfroms_empwheredept_idin(41,42,50);顺序对最终结果没有影响但对效率可能产生影响字段isnull判断一个字段是不是NULLid是1的人manager_id是不是NULLselectid,first_namefroms_empwheremanager_idisnull;like-----模糊查询成龙配套成龙李小龙龙飞凤舞first_name中带a字符的统配符:%代表n个任意字符_一个任意字符'%a%''%a''a%''_a%''%a_'selectfirst_namefroms_empwherefirst_namelike'%a%';找出第二个字符是aselectfirst_namefroms_empwherefirst_namelike'_a%';user_tables----数据字典表,存储了数据库中所有表的信息descuser_tablesTABLE_NAME表名selecttable_namefromuser_tables;s_emps_depts找出所有s_开头的表名selecttable_namefromuser_tab...