日期:2014-05-16 浏览次数:20700 次
1. select * from emp;
2. select empno, ename, job from emp;
3. select empno 编号, ename 姓名, job 工作 from emp;
4. select job from emp;
5. select distinct job from emp;
6. select distinct empno, job from emp;
说明:因为雇员编号不重复, 所以此时证明所有的列没有重复,所以不能消除掉重复的列.
7. 查询出雇员的编号, 姓名, 工作, 但是显示的格式:编号是: 7369 的雇员, 姓名是: smith, 工作是: clear
select '编号是: ' || empno || '的雇员, 姓名是: ' || ename || ', 工作是: ' || job from emp;
8. 求出每个雇员的姓名及年薪
select ename, sal * 12 income from emp;
9. 求出工资大于 1500 的所有雇员信息
select * from emp where sal > 1500;
10. 查询每月可以得到奖金的雇员信息
select * from emp where comm is not null;
11. 查询没有奖金的雇员信息
select * from emp where comm is null;
12. 查询出基本工资大于 1500 同时可以领取奖金的雇员信息
select * from emp where sal > 1500 and comm is not null;
13. 查询出基本工资大于 1500 或者可以领取奖金的雇员信息
select * from emp where sal > 1500 or comm is not null;
14. 查询出基本工资不大于 1500 或者不可以领取奖金的雇员信息
select * from emp where not(sal > 1500 and comm is not null);
15. 查询基本工资大于 1500, 但是小于 3000 的全部雇员信息
select * from emp where sal > 1500 and sal < 3000;
16. 查询基本工资大于等于 1500, 但是小于等于 3000 的全部雇员信息
select * from emp where sal >= 1500 and sal <= 3000;
select * from emp where sal between 1500 and 3000;
17. 查询出在 1981 年雇佣的全部雇员信息(1981 年 1 月 1 日 到 1981 年 12 月 31 日之间的雇佣的雇员)
select * from emp where hiredate between '1-1月-81' and '31-12月-81';
18. 要求查询出姓名是 smith 的雇员信息
select * from emp where ename = 'SMITH';
19. 要求查询出雇员是 7369, 7499, 7521 的雇员的具体信息
select * from emp where empno = 7369 or empno = 7499 or empno = 7521;
select * from emp where empno in(7369, 7499, 7521);
20. 要求查询出雇员不是 7369, 7499, 7521 的雇员的具体信息
select * from emp where empno not in(7369, 7499, 7521);
21. 要求查询出姓名是 smith, allen, king 的雇员信息
select * from emp where ename in('SMITH', 'ALLEN', 'KING');
22. 查询出所有雇员姓名中第二个字母包含 "M" 的雇员信息
select * from emp where ename like '_M%';
23. 查询出雇员姓名中包含字母 M 的雇员信息
select * from emp where ename like '%M%';
24. 要求查询出在 1981 年雇佣的雇员信息
select * from emp where hiredate like '%81%';
25. 查询工资中包含 5 的雇员信息
select * from emp where sal like '%5%';
26. 查询雇员编号不是 7369 的雇员信息
select * from emp where empno != 7369;
select * from emp where empno <> 7369;
27. 要求按照工资由低到高排序
select * frm emp order by sal;
select * from emp order by sal asc;
28. 要求按照工资由高到低排序
select * from emp order by sal desc;
29. 要求查询出 20 部门的所有雇员信息, 查询的信息按照工资由高到低排序,如果工资相等,则按照雇佣日期由早到晚排序.
select * from emp where deptno = 20 order by sal desc, hiredate asc;
30. 将小写字母变为大写字母
select upper('hello') from dual;
31. 将大写字母变为小写字母
select lower('HELLO WORLD') from dual;
32. 要求查询出姓名是 smith 的雇员信息
select * from emp where ename = upper('smith');
33. 使用 initcap() 函数将单词的第一个字母大写
select initcap('hello world') from dual;
34. 将雇员表中的雇员姓名变为开头字母大写
select initcap(ename) from emp;
35. 将字符串 "hello" 和 "world" 进行串联
select concat('hello ', 'world') from dual;
36. 对字符串进行操作的常用字符处理函数
select substr('hello', 1, 3) 截取字符串, length('hello') 字符串的长度, replace('hello', 'l', 'x') 字符串替换 from dual;
select substr('hello', 0, 3) 截取字符串, length('hello') 字符串的长度, replace('hello', 'l', 'x') 字符串替换 from dual;
37. 显示所有雇员的姓名及姓名的后三个字符
select ename, substr(ename, length(ename) -2) from emp;
select ename, substr(ename, -3, 3) from emp;
38. 使用数值函数执行四舍五入操作
select round(789.536) from dual;
39. 要求将 789.536 数值保留两位小数
select round(789.536, 2) from dual;
40. 要求将 789.536 数值中的整数的十位进行四舍五入进位
select round(789.536, -2) from dual;
41. 采用 t