Oracle 分頁的三種情況

來源:互聯網
上載者:User

Oralce 的分頁一共有三種

1. rownum

select *  from emp

2. 顯示rownum[Oracle 分配的]

select a1.* ,rownum rn from (select * from emp) a1;

3.幾個查詢的變化

a.指定查詢列只需修改最裡層的子查詢就可以了

b.排序也是只需要修改最裡面的就可以了

----------------------------------------------------------

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 cid desc;

執行時間為0.03秒

2.按分析函數來分

select * from (select t.* ,row_number() over(order by cid

desc ) rk from t_xiaoxi t ) where rk<10000 and rk>9980;

執行時間為1.01 秒

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.1秒

其中—t_xiaoxi 為表名,cid為表的關鍵字段,取按CId降序排序

後的第9981-9999條記錄,t_xiaoxi 表中有70000多條記錄

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.