【Oracle】模糊查询与高级连接查询
2016-11-02 22:21
405 查看
区间和范围查询
Between … and 的用法//查询薪水在2000-3000之间的员工信息 select * from emp where sal>=2000 and sal<=3000l or select * from emp where sal 2000 and 3000;
is null(空字符串)
//查询没有上级的员工信息 select * from emp where mgr is null;
模糊查询 (like ‘%关键字%’)
//查询薪水高于2000或者岗位为CLERK的员工信息,同时还要满足其姓名首字母为'J'的信息 select * from emp where (sal>2000 or job='CLERK') and ename like'J%';
高级连接查询
内连接查询//内连接查询(返回两张表共同的数据) select * from 表1 inner join 表2 on 表1.公共列 = 表2.公共列;
左外连接查询
select * from 表1 left join 表2 on 表1.公共列 = 表2.公共列;
右外连接查询
select * from 表1 right join 表2 on 表1.公共列 = 表2.公共列;
完全连接查询
select * from 表1 full join 表2 on 表1.公共列 = 表2.公共列;
交叉连接(笛卡尔积)
select * from 表1,表2 where 表1.公共列 = 表2.公共列;
自连接查询(自己查询自己)
//查询员工‘SMITH’的上级领导姓名 //方式一 子查询 select * from emp where empno = (select mgr from emp where ename='SMITH'); //方式二 一个查询结果作为一个新表 select * from (select mgr from emp where ename='SMITH') 上级表 inner join emp on 上级表.mgr = emp.empno; //方式三 select * from emp,(select mgr from emp where ename='SMITH') 上级表 where emp.empno = 上级表.mgr;
子查询(在SQL语句中嵌套的查询)
单行子查询//单行子查询:返回一个值的子查询 = > < >= <= //查询与‘SMITH’同部门的员工 select * from emp where deptno = (select deptno from emp where emp.ename='SMITH');
多行子查询 (in / not in)
//查询与部门10号员工同岗位的员工 select * from emp where job in (select job from emp where deptno=10)
多列子查询
//查询与'SMITH'同部门岗位的员工 select * from emp where (deptno.job) = (select deptno,job from emp where ename='SMITH');
内联视图子查询
//内联视图子查询:将子查询的结果作为另一个查询的数据源 //查询薪水最低的5个员工的信息 //注:因为rownum是先序列再排序,不能直接select * from 表名 order //by列 where rownum<5,所以先把排序的结果集在rownum序列一次 select rownum,t1.* from (select emp.* from emp order by sal asc) t1 where rownum<=5; //查询员工信息表1-5行的数据 select t1.* from (select rownum r,emp.* from emp where rownum <=10) t1 where r>5 and r<=10;
分页查询
//每页有多少行(PageCount),当前第几页(Page) select t1.* from (select rownum r,emp.* from where rownum<=pagecount*page) t1 where r>pagecount*(page-1) and r<=pagecount*page;
相关文章推荐
- oracle高级查询之连接查询、集合运算
- SQl Server与Oracle的高级模糊查询
- Oracle查找排序,模糊查询,外连接
- mybatis 连接 oracle模糊查询concat关键字
- oracle的高级查询 多表的连接
- Oracle查找排序,模糊查询,外连接
- oracle 参数的模糊查询的问题
- Oracle高级查询
- Oracle SQL模糊查询的语法为
- Oracle高级查询
- 查询oracle当前连接数
- [转]ORACLE中的模糊查询
- oracle 存储过程支持模糊查询
- Windchill中实现like模糊查询字段中包含“_”和“%”的高级查询
- oracle外连接查询
- oracle sql语言模糊查询--通配符like的使用教程
- oracle和sqlserver 的模糊查询是一致的
- ORACLE连接类型 各种连接查询PL/SQL测试
- [转] Oracle外连接查询
- Oracle 数据库连接查询SQL语句