1、Oracle sql语句(<>,any,some,all,is null,is not null,between * and *,in(list),not in(list),exits,like)

    科技2026-02-27  5

     

    --!=不等于 select * from emp where deptno !=20; --<>不等于 select * from emp where deptno <>20; --any,取其中任意一个 select sal from emp where sal>any(1000,1500,3000); --some,some跟any是同一个效果,只要大于其中某一个值都会成立 select sal from emp where sal>some(1000,1500,3000); --all,大于所有的值才会成立 select sal from emp where sal>all(1000,1500,3000); --is null为空 select * from emp where comm is null; --is not null非空 select * from emp where comm is not null; --between x and y,包含x和y的值 select * from emp where sal between 1500 and 3000; --需要进行某些值的等值判断的时候可以使用in 和not in --in(list), select * from emp where deptno in(10,20); --not in(list), select * from emp where deptno not in(10,20); --exits(sub-query) --通过外层循环来规范内层循环 select * from emp e where exists(select deptno from dept d where (d.deptno = 10 or d.deptno = 20) and e.deptno = d.deptno) --like --查询名字以S开头的用户 --在like的语句中,需要使用占位符或者通配符 --_表示某个字符或者数字仅出现一次 --%表示任意字符出现任意次数 --以下查询名字以S开头的用户 select * from emp where ename like('S%') --以下查询名字以S开头且倒数第二个字符为T的用户 select * from emp where ename like('S%T_'); 练习题: --查询部门编号为10的员工信息 select * from emp where deptno=20 --查询年薪大于3万的人员的姓名与部门编号 select empno,ename from emp where (sal * 12)>30000 --查询佣金为null的人员姓名与工资 select ename,sal from emp where comm is null --查询工资大于1500且and含有佣金的人员姓名 select ename from emp where sal >1500 and comm is not null --查询工资大于1500或or含用佣金的人员姓名 select ename from emp where sal>1500 or comm is not null --查询姓名里面含有S员工信息 工资、名称 select ename,sal from emp where ename like('%S%') --求姓名以J开头第二个字符O的员工姓名与工资 select ename,sal from emp where ename like('JO%') --使用in查询部门名称为SALES和RESEARCH的雇员姓名、工资、部门编号 select e.ename, e.sal, e.deptno from emp e where e.deptno in (SELECT deptno from dept d where d.dname = 'SALES' or d.dname = 'RESEARCH') --order by进行排序操作 select * from emp order by sal;--默认情况为升序排序 select * from emp order by sal desc;--降序

     

    Processed: 0.011, SQL: 9