1、分页查询
oracle分页一共有三种
1、rownum分页
(select * from emp)
2、显示rownum[oracle分配的]
select a1.*,rownum rn from (select * from emp) a1;
3、
按雇员的id号升序取出
select a1.* ,rownum rn from (select * from emp) a1;
取出编号10以下的雇员
select a1.*,rownum rn from (select * from emp) a1,where rownum<=10;
取出编号6-10的雇员
select * from (select a1.*,rownum rn from (select * from emp) a1 where rownum<=10) where rn<=6;
4、几个查询变化
①指定查询列,只需修改最里层的子查询
select * from (select a1.*,rownum rn from (select ename,sal from emp) a1 where rownum<=10) where rn>=6;
②如何排序,只需修改最里层的子查询
select * from (select a1.*,rownum rn from (select ename,sal from emp order by sal) a1 where rownum<=10) where rn>=6;
--------------------------------------------------------------------------------------------------------------------------------------------------------------
1、根据ROWID来分
select * from t_xiaoxi where rowid in (select rid from (select rownum rn,rid from (select rowid rid,cid from t_xiaoxi order by cid desc) where rownum<10000) where rn>9980) order by desc;
执行时间0.03s
2、按分析函数来分
select * from (select t.*,row_number() over(order by cid desc) rk from t_xiaoxi t) where rk<10000 and rk>9980;
执行时间1.01s
3、按ROWNUM来分
select * from (select t.*,rownum rn from (select * from t_xiaoxi order by cid desc) t where rownum<10000) where rn>9980;
执行时间0.1s
其中t_xiaoxi为表名称,cid为表的关键字段,取按CID降序排序后的第9981-9999条记录,t_xiaoxi表有70000多条记录
//测试通过的分页查询
select * from (select a1.*,rownum rn from (select ename,job from emp) a1 where rownum<=10) where rn>=5;