资源描述:
《【优秀文档】Oracle 总结 (1)(整理版).doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、OracleSQLdatebase(DB)Structuredquerylanguage结构化查询语言DDL(数据定义语言)Datedefinitionlanguagecreatetable建表altertable修改表结构droptable删表columndatatypewidthconstraints(约束)DML(数据操作语言)DatamanipulationlanguageinsertupdatedeletedatarowrecordTCL(事物控制语句)Transcationcontrollanguagec
2、ommit(提交)rollback(回滚)savepointDQL(数据查询语言)DataquerylanguageselectInstallsoftwarerdbms安装软件createdatabase创建数据库登录数据库sqlplususername/passvvordORACLE_SID(环境变量)数据库对应的实例的名字,该名字决定了连接哪个具体的数据库showuser查看当前用户desctablename査看表结构descdescribe的缩写查询员工的姓名,和工资selectfirst_name,salar
3、yfroms_emp;査询员工的名字和职位selectfirst_name4itlefroms_emp;edit修改sql语句1查看/运行select*froms_dept;列出部门表的所有信息列出每个员工的年薪selecttirst_name,salary*12froms_emp;列出每个员工的总收入selectfirst_name,salary*12*(l+commission_pct/100)ntolsal"froms_emp;空值会导致算术表达式为空,Oracle认为null为无穷大selectfirst_n
4、ame^salary*12*(l+nvl(commission_pct,0)/100)tol_sal,Commission_pctfroms_empnvl(pl,p2)if(plisnull)thenreturnp2;elsereturnpl;coalesce和nvl实现的是同样的功能,nvl只能用在Oracle,coalesce可以用在多种数据库,nvl的两个参数的类型必须一致给列起别名在列后直接跟别名,别名有空格,或者大小写敏感,要给别名加“”将姓和名拼接起来’表示字符串”表示别名,II表示字符串的拼接selec
5、tfirst_namelllast_nameemployeefroms_emp;selecttirst_namel「1lllast_nameemployeefroms_emp;selectfirst_namellfisindepartmentflldept_idir.ffroms_emp;列出有哪些部门selectdistinctnamefroms_dept;distinct去重(mill值夜只保留一个),只能放在select后列出公司有哪些不同的职位selectdistincttitlefroms_emp;setf
6、eedon显示査询返回的记录数各个部门有哪些不同的职位selecttitle,dept_idfroms_emp;部门号和职位联合起来唯一列出工资大于1000的员工selecttirst_name,salaryfroms_empwheresalary>1000;年薪大于12000的员工(where语句后的字段最好不要使用表达式,影响效率)selectfirst_name^salary*12froms_empwheresalary>1000;where子句不能跟列的别名列出Carmen的年薪selectfirst_nam
7、e,salaryfroms_empwhereflrst_name=1Carmen1;哪些人的职位是StockClerkselectfirst_name4itlefroms_empwheretitle=fStockClerk1;哪些员工的工资在1550-2000之间selectfirst_name^salaryfroms_empwheresalary>=1550andsalary<=2000;selectfirst_name,salaryfroms_empwheresalarybetween1550and2000;列出
8、部门号为31,41,43的员工的工资selectfirst_name^salary,dept_idfroms_empwheredept_id=31ordept_id=41ordept_id=43;selectfirst_name,salary,dept_idfroms_empwheredept_idin(31,41,43);selectfirs