oracle where ( ) = 值,Oracle系列:(6)where子句

查询emp表中20号部门的员工信息select * from emp where deptno = 20;

查询姓名是SMITH的员工,字符串使用'',内容大小写敏感select * from emp where ename = 'SMITH';

总结:你所学过的技术中,哪些是大小写敏感,哪些是大小写不敏感

c8ff10dafc84a600149b9a804a9214bd.png

查询1980年12月17日入职的员工,注意oracle默认日期格式(DD-MON-RR表示2位的年份)select * from emp where hiredate = '17-12月-80';

查询工资大于1500的员工select * from emp where sal > 1500;

查询工资不等于1500的员工【!=或<>】select * from emp where sal <> 1500;

查询薪水在1300到1600之间的员工,包括1300和1600 【between应用于数字】select * from emp where (sal>=1300) and (sal<=1600);

或select * from emp where sal between 1300 and 1600;

查询薪水不在1300到1600之间的员工,不包括1300和1600 【not between】select * from emp where sal NOT between 1300 and 1600;

查询入职时间在"1981-2月-20"到"1982-1月-23"之间的员工【between应用于日期】select * from emp where hiredate between '20-2月-81' and '23-1月-82';

33bf520fefe826aa384ca21b01630fae.png

注意:

1)对于数值型,小数值在前,大数值在后

2)对于日期型,年长值在前,年小值在后

查询20号或30号部门的员工,例如:根据ID号,选中的员工,批量删除【in】select * from emp where (deptno=20) or (deptno=30);

或select * from emp where deptno in (30,20);

查询不是20号或30号部门的员工【not in】select * from emp where deptno NOT in (30,20);

查询姓名以大写字母S开头的员工,使用%表示0个,1个或多个字符【like模糊查询】

select * from emp where ename like 'S';

等价

select * from emp where ename = 'S';select * from emp where ename like 'S%';

71d79c71b58e3123598289e7d75c9faf.png

注意:

凡是精确查询用=符号

凡是不精确查询用like符号,我们通常叫模糊查询

查询姓名以大写字母N结束的员工select * from emp where ename like '%N';

查询姓名第一个字母是T,最后一个字母是R的员工select * from emp where ename like 'T%R';

查询姓名是4个字符的员工,且第二个字符是I,使用_只能表示1个字符,不能表示0个或多个字符select * from emp where ename like '_I__';

a1f39bb089eb6d057bff9c037c0cadb1.png

插入一条姓名为'T_IM'的员工,薪水1200

insert into emp(empno,ename) values(1111,'T_IM');

查询员工姓名中含有'_'的员工,使用\转义符,让其后的字符回归本来意思【like '%\_%' escape '\'】select * from emp where ename like '%\_%' escape '\';

7eb1da14d04ec2aa2342ce7514fcfa5e.png

插入一个姓名叫'的员工insert into emp(empno,ename) values(2222,'''');

插入一个姓名叫''的员工insert into emp(empno,ename) values(2222,'''''');

4cbf4d7a3308fc419baf8c166abe7454.png

4d2ae0f5abf5a5d99c4b19179d2651b8.png

查询所有员工信息,使用%或%%select * from emp;

select * from emp where ename like '%';

select * from emp where ename like '%_%';

查询佣金为null的员工【is null】select * from emp where comm is null;

ce9a6ce016e33ab8f444ef17c914fbf1.png

注意:null不能参与=运算

null能参与number/date/varchar2类型运算

查询佣金为非null的员工【is not null】

select * from emp where comm is not null;

查询无佣金且工资大于1500的员工select *

from emp

where (comm is null) and (sal>1500);

查询工资是1500或3000或5000的员工select *

from emp

where sal in (4000,10000,1500,3,300,3000,5000);

查询职位是"MANAGER"或职位不是"ANALYST"的员工(方式一,使用!=或<>)select *

from emp

where (job='MANAGER') or (job<>'ANALYST');

查询职位是"MANAGER"或职位不是"ANALYST"的员工(方式二,使用not)select *

from emp

where (job='MANAGER') or (not(job='ANALYST'));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值