-----oracle的分页查询
--问题:当一个表中的数据量特别大的时候,如果一次性全部显示给用户,则造成页面过于庞大,体验极差。
--解决:使用分页查询
--使用:
--rownum关键字:oracle对外提供的自动给查询结果编号的关键字,与每行的数据没有关系。
--注意:rownum关键字只能做< <=的判断,不能进行> >=的判断
select rownum ,e.* from emp e;
--查询员工信息的前5条数据 第一页数据
select rownum r,e.* from emp e where rownum <=5;
select * from (select rownum r,e.* from emp e where rownum <=5) t where r>0;
--查询员工信息的6-10条数据 第二页数据
select rownum r,e.* from emp e where rownum <=10;
select rownum,t.* from (select rownum r,e.* from emp e where rownum <=10) t where r>5;
--查询员工信息的11-15条数据 第三页数据
select rownum r,e. * from emp e where rownum<=15;
select * from (select rownum r,e. * from emp e where rownum<=15) t where r>10;
--分页规律总结:每页显示m条数据,查询第n页数据
select * from (select rownum r,e. * from 要分页的表 e where rownum<=m*n) t where r>m*n-m ;
--要分页的表既可以是真实的表,也可以是一个查询语句
--分页查询员工信息按照工资排序
select * from (select rownum r,t.* from (select * from emp order by sal) t where rownum<=10 ) where r>5
select * from t
select * from emp
oracle中的分页查询
1、没有排序的情况下查询
select * from emp
select rownum ,e.* from emp e where rownum<=5
select * from (select rownum r,e.* from emp e where rownum<=10) t where r>5
2、有排序的情况下的查询
select * from emp order by sal
select rownum r,e.* from (select * from emp order by sal) e where rownum <=5
select * from (select rownum r,e.* from (select * from emp order by sal) e where rownum <=10) t where r>5
select * from (select rownum r,e.* from (select * from emp order by sal) e where rownum <=m*n) t where r>m*(n-1)