限定查询就是根据限定的条件查询出想要的内容,就是在之前的简单查询上增加了where条件,在where中可以增加多个条件,最常见的条件就是基本关系运算,如:>,<,=,>=,<=,!=(<>),between..and,like,in,is null,and,or,not等
很简单,几个例子足以说明这个问题:
1.关系运算
①查询出工资大于1500的员工:
select * from emp where sal>1500;
②查询出 员工是 JONES的信息:
select * from emp where ename='JONES';
注:在oracle中是严格区分大小写的!!!
③查询出 职位是销售人员,或者是办事员的基本信息:
select * from emp where job='SALESMAN' or job='CLERK';
④查询出 职位是销售人员,或者是办事员的基本信息,并且工资大于1500:
select * from emp where (job='SALESMAN' or job='CLERK') and sal>1500;
这个运算有优先级,但是我们在写语句的时候一般都是用括号改变运算的优先级,如上所示,如果没有加括号,就会出现工资低于1500的结果。
⑤查询出所有不是销售人员的信息:
这个有三种写法,如下:
select * from emp where job<>'SALESMAN';
select * from emp where job!='SALESMAN';
select * from emp where not job='SALESMAN';
2.范围操作 between...and
如下:我们查询工资在1000到1500的雇员:
select * from emp where sal between 1000 and 1500;
求反:
select * from emp where not sal between 1000 and 1500;
3.判断一个值是否为空:
is (not )null
如查询出所有领取奖金的雇员:
select * from emp where comm is not null;
select * from emp where not comm is null;
4.指定范围的判断:in操作符
例如,我们要查询出员工号是 7788,7369,7934
select * from emp where empno in (7788,7934,7369);
not in 是指不在指定范围内的结果
注:如果在in 的查询范围内出现了 null 则不影响查询结果。如果在not in中出现了null 则表示查询全部数据。
5.模糊查询:like查询
匹配单个字符:“_”
匹配任意字符:“%”
①查询名字中包含A的员工:
select * from emp where ename like 'A%';
②查询第二个字母是A的员工:
select * from emp where ename like '_A%';
③查询员工名字中带有A的:
select * from emp where ename like '%A%';
select * from emp where ename not like 'A%'; 查询第一个字母不是A的员工
注:like 查询子句可以再任何的字段,不只是局限于字符串。
如果like中不设置任何查询条件 如 %% 即可认定是查询全部内容
















