Oracle--分页

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;

转载于:https://www.cnblogs.com/ZKeJun/p/8940088.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值