文档详情

oracle入门经典(单表操作).doc

发布:2016-09-19约8.11千字共14页下载文档
文本预览下载声明
oracle入门经典(单表操作) /* 以下代码是对emp表进行显示宽度设置 */ col empno for 9999; col ename for a10; col job for a10; col mgr for 9999; col hiredate for a12; col sal for 9999; col comm for 9999; col deptno for 99; set pagesize 20; 查询scott用户下的所有表 select * from tab; 查询当前用户是谁 show user; 设置显示的列宽(字符型),10个字符宽度 col tname for a10; 执行最近一次的SQL语句,并不是SQLPLUS命令 / 清屏 host cls; 查询emp表的结构 desc emp; 查询emp表的所有内容 select * from emp; 设置显示的列宽(数字型),9表示数字型,一个9表示一个数字位,四个9表示四个数字位 col empno for 9999; 设置在一页中显示20条记录 set pagesize 20; 查询emp表的员工编号,姓名,工资,部门号 select empno,ename,sal,deptno from emp; 查询emp表的不重复的工作 select distinct job from emp; 查询员工的编号,姓名,月薪,年薪 select empno,ename,sal,sal*12 from emp; 修改上一条SQL语句 edit; 查询员工的编号,姓名,月薪,年薪,年收入(年薪+奖金有空值) select empno,ename,sal,sal*12,sal*12+comm from emp; 解决null的问题,使用NVL()函数 select empno,ename,sal,nvl(comm,0) from emp; NVL(a,b):如果a是空,用b替代 select empno,ename,sal,sal*12,sal*12+nvl(comm,0) from emp; 使用别名,查询员工的编号,姓名,月薪,年薪,年收入(年薪+奖金) select empno as 编号,ename as 姓名,sal as 月薪,sal*12 as 年薪,sal*12+nvl(comm,0) as 年收入 from emp; select empno 编号,ename 姓名,sal 月薪,sal*12 年薪,sal*12+nvl(comm,0) 年 收 入 from emp; select empno 编号,ename 姓名,sal 月薪,sal*12 年薪,sal*12+nvl(comm,0) 年收入 from emp; 提倡列名使用号下界 使用字符串连接符号,输出hello world select Hello || World 结果 from dual; 显示系统当前时间 select sysdate from dual; Oracle默认日期格式为:DD(2位日)-MON(月的简写)-RR(2位年) 使用字符串连接符号,显示如下格式信息:xxxx的薪水是xxxx select ename || 的工资是 || sal || 元 AS 薪水情况 from emp; 保存SQL语句到文件 spool d:\1234.sql; 保存SQL语句及其执行的结果 spool off; 执行文件中的sql语句,该文件必须是*.sql文件 @ d:\1234.sql; 单行注释 --单行注释 多行注释 select * /* 这是 多行 注释 */ from emp; 查询10号部门的员工 select * from emp where deptno=10; 查询姓名是KING的员工,字符串值,大小写敏感 select * from emp where ename=KING; 查询1981年11月17日入职的员工,17-11月-81满足oracle默认日期格式(DD-MON-RR表示2位的年份) select * from emp where hiredate=17-11月-81; 查询工资大于1500的员工 select * from emp where sal1500; select * from emp where sal!=1500; 查询薪水在1300到1600之间的员工 select * from emp where sal between 1300 and 1600; 查询入职时间在20-2月-81到23-1月-82之间
显示全部
相似文档