oracle数据库常用的99条查询语句Word文件下载.docx
《oracle数据库常用的99条查询语句Word文件下载.docx》由会员分享,可在线阅读,更多相关《oracle数据库常用的99条查询语句Word文件下载.docx(11页珍藏版)》请在冰豆网上搜索。
,工作是:
||jobfromemp;
8.求出每个雇员的姓名及年薪
selectename,sal*12incomefromemp;
9.求出工资大于1500的所有雇员信息
select*fromempwheresal>
1500;
10.查询每月可以得到奖金的雇员信息
select*fromempwherecommisnotnull;
11.查询没有奖金的雇员信息
select*fromempwherecommisnull;
12.查询出基本工资大于1500同时可以领取奖金的雇员信息
1500andcommisnotnull;
13.查询出基本工资大于1500或者可以领取奖金的雇员信息
1500orcommisnotnull;
14.查询出基本工资不大于1500或者不可以领取奖金的雇员信息
select*fromempwherenot(sal>
1500andcommisnotnull);
15.查询基本工资大于1500,但是小于3000的全部雇员信息
1500andsal<
3000;
16.查询基本工资大于等于1500,但是小于等于3000的全部雇员信息
=1500andsal<
=3000;
select*fromempwheresalbetween1500and3000;
17.查询出在1981年雇佣的全部雇员信息(1981年1月1日到1981年12月31日之间的雇佣的雇员)
select*fromempwherehiredatebetween'
1-1月-81'
and'
31-12月-81'
;
18.要求查询出姓名是smith的雇员信息
select*fromempwhereename='
SMITH'
19.要求查询出雇员是7369,7499,7521的雇员的具体信息
select*fromempwhereempno=7369orempno=7499orempno=7521;
select*fromempwhereempnoin(7369,7499,7521);
20.要求查询出雇员不是7369,7499,7521的雇员的具体信息
select*fromempwhereempnonotin(7369,7499,7521);
21.要求查询出姓名是smith,allen,king的雇员信息
select*fromempwhereenamein('
'
ALLEN'
KING'
);
22.查询出所有雇员姓名中第二个字母包含"
M"
的雇员信息
select*fromempwhereenamelike'
_M%'
23.查询出雇员姓名中包含字母M的雇员信息
select*fromempwhereenamelike'
%M%'
24.要求查询出在1981年雇佣的雇员信息
select*fromempwherehiredatelike'
%81%'
25.查询工资中包含5的雇员信息
select*fromempwheresallike'
%5%'
26.查询雇员编号不是7369的雇员信息
select*fromempwhereempno!
=7369;
select*fromempwhereempno<
>
7369;
27.要求按照工资由低到高排序
select*frmemporderbysal;
select*fromemporderbysalasc;
28.要求按照工资由高到低排序
select*fromemporderbysaldesc;
29.要求查询出20部门的所有雇员信息,查询的信息按照工资由高到低排序,如果工资相等,则按照雇佣日期由早到晚排序.
select*fromempwheredeptno=20orderbysaldesc,hiredateasc;
30.将小写字母变为大写字母
selectupper('
hello'
)fromdual;
31.将大写字母变为小写字母
selectlower('
HELLOWORLD'
32.要求查询出姓名是smith的雇员信息
select*fromempwhereename=upper('
smith'
33.使用initcap()函数将单词的第一个字母大写
selectinitcap('
helloworld'
34.将雇员表中的雇员姓名变为开头字母大写
selectinitcap(ename)fromemp;
35.将字符串"
hello"
和"
world"
进行串联
selectconcat('
hello'
world'
36.对字符串进行操作的常用字符处理函数
selectsubstr('
1,3)截取字符串,length('
)字符串的长度,replace('
l'
x'
)字符串替换fromdual;
0,3)截取字符串,length('
37.显示所有雇员的姓名及姓名的后三个字符
selectename,substr(ename,length(ename)-2)fromemp;
selectename,substr(ename,-3,3)fromemp;
38.使用数值函数执行四舍五入操作
selectround(789.536)fromdual;
39.要求将789.536数值保留两位小数
selectround(789.536,2)fromdual;
40.要求将789.536数值中的整数的十位进行四舍五入进位
selectround(789.536,-2)fromdual;
41.采用trunc()函数不会保留任何小数,而且小数点也不会执行四舍五入的操作
selecttrunc(789.536)fromdual;
42.通过trunc()也可以指定小数点的保留位数
selecttrunc(789.536,2)fromdual;
43.作用负数表示位数
selecttrunc(789.536,-2)fromdual;
44.使用mod()函数可以进行取余的操作
selectmod(10,3)fromdual;
45.显示10部门雇员进入公司的星期数(当前日期-雇佣日期=天数/7=星期数)
selectempno,ename,round((sysdate-hiredate)/7)fromempwheredeptno=10;
46.日期函数
months_between():
求出给定日期范围的月数
add_months():
在指定的日期上加上指定的月数,求出之后的日期
next_day():
指定日期的下一个日期
last_day():
求出给定日期当月的最后一天日期
47.
selectempno,ename,months_between(sysdate,hiredate)fromemp;
selectempno,ename,round(months_between(sysdate,hiredate))fromemp;
48.selectsysdate,add_months(sysdate,4)fromdual;
49.selectnext_day(sysdate,'
星期一'
50.selectlast_day(sysdate)fromdual;
51.转换函数
to_char():
转换成字符串
to_number():
转换成数字
to_date():
转换成日期
52.查询所有雇员的雇员编号,姓名,雇佣日期
selectempno,
ename,
to_char(hiredate,'
yyyy'
)year,
mm'
)months,
dd'
)day
fromemp;
selectempno,ename,to_char(hiredate,'
yyyy-mm-dd'
)fromemp;
fmyyyy-mm-dd'
53.查询所有雇员的编号,姓名和工资
selectempno,ename,salfromemp;
selectempno,ename,to_char(sal,'
99,999'
L99,999'
$99,999'
54.selectto_number('
123'
)+to_number('
55.将一个字符串转换成日期类型
selectto_date('
2009-01-01'
56.求出每个雇员的年薪(要求加上奖金)
selectempno,ename,sal,comm,(sal+comm)*12fromemp;
selectempno,ename,sal,comm,nvl(comm,