oracle数据库常用的99条查询语句.docx

上传人:b****2 文档编号:1175531 上传时间:2022-10-18 格式:DOCX 页数:11 大小:18.52KB
下载 相关 举报
oracle数据库常用的99条查询语句.docx_第1页
第1页 / 共11页
oracle数据库常用的99条查询语句.docx_第2页
第2页 / 共11页
oracle数据库常用的99条查询语句.docx_第3页
第3页 / 共11页
oracle数据库常用的99条查询语句.docx_第4页
第4页 / 共11页
oracle数据库常用的99条查询语句.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

oracle数据库常用的99条查询语句.docx

《oracle数据库常用的99条查询语句.docx》由会员分享,可在线阅读,更多相关《oracle数据库常用的99条查询语句.docx(11页珍藏版)》请在冰豆网上搜索。

oracle数据库常用的99条查询语句.docx

oracle数据库常用的99条查询语句

1.select*fromemp;

2.selectempno,ename,jobfromemp;

3.selectempno编号,ename姓名,job工作fromemp;

4.selectjobfromemp;

5.selectdistinctjobfromemp;

6.selectdistinctempno,jobfromemp;

说明:

因为雇员编号不重复,所以此时证明所有的列没有重复,所以不能消除掉重复的列.

7.查询出雇员的编号,姓名,工作,但是显示的格式:

编号是:

7369的雇员,姓名是:

smith,工作是:

clear

select'编号是:

'||empno||'的雇员,姓名是:

'||ename||',工作是:

'||jobfromemp;

8.求出每个雇员的姓名及年薪

selectename,sal*12incomefromemp;

9.求出工资大于1500的所有雇员信息

select*fromempwheresal>1500;

10.查询每月可以得到奖金的雇员信息

select*fromempwherecommisnotnull;

11.查询没有奖金的雇员信息

select*fromempwherecommisnull;

12.查询出基本工资大于1500同时可以领取奖金的雇员信息

select*fromempwheresal>1500andcommisnotnull;

13.查询出基本工资大于1500或者可以领取奖金的雇员信息

select*fromempwheresal>1500orcommisnotnull;

14.查询出基本工资不大于1500或者不可以领取奖金的雇员信息

select*fromempwherenot(sal>1500andcommisnotnull);

15.查询基本工资大于1500,但是小于3000的全部雇员信息

select*fromempwheresal>1500andsal<3000;

16.查询基本工资大于等于1500,但是小于等于3000的全部雇员信息

select*fromempwheresal>=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('SMITH','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')fromdual;

32.要求查询出姓名是smith的雇员信息

select*fromempwhereename=upper('smith');

33.使用initcap()函数将单词的第一个字母大写

selectinitcap('helloworld')fromdual;

34.将雇员表中的雇员姓名变为开头字母大写

selectinitcap(ename)fromemp;

35.将字符串"hello"和"world"进行串联

selectconcat('hello','world')fromdual;

36.对字符串进行操作的常用字符处理函数

selectsubstr('hello',1,3)截取字符串,length('hello')字符串的长度,replace('hello','l','x')字符串替换fromdual;

selectsubstr('hello',0,3)截取字符串,length('hello')字符串的长度,replace('hello','l','x')字符串替换fromdual;

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,'星期一')fromdual;

50.selectlast_day(sysdate)fromdual;

51.转换函数

to_char():

转换成字符串

to_number():

转换成数字

to_date():

转换成日期

52.查询所有雇员的雇员编号,姓名,雇佣日期

selectempno,

ename,

to_char(hiredate,'yyyy')year,

to_char(hiredate,'mm')months,

to_char(hiredate,'dd')day

fromemp;

selectempno,ename,to_char(hiredate,'yyyy-mm-dd')fromemp;

selectempno,ename,to_char(hiredate,'fmyyyy-mm-dd')fromemp;

53.查询所有雇员的编号,姓名和工资

selectempno,ename,salfromemp;

selectempno,ename,to_char(sal,'99,999')fromemp;

selectempno,ename,to_char(sal,'L99,999')fromemp;

selectempno,ename,to_char(sal,'$99,999')fromemp;

54.selectto_number('123')+to_number('123')fromdual;

55.将一个字符串转换成日期类型

selectto_date('2009-01-01','yyyy-mm-dd')fromdual;

56.求出每个雇员的年薪(要求加上奖金)

selectempno,ename,sal,comm,(sal+comm)*12fromemp;

selectempno,ename,sal,comm,nvl(comm,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 计算机软件及应用

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1