Oracle 分頁的三種實現

來源:互聯網
上載者:User

1.Oracle資料庫分頁的三種實現 速度最快  1 > 2 > 3

第一種採用rowid   4層  
第二種是用 rownum分頁 3 層 (oracle規定:每次查詢中 rownum只能用一次)  
第三種是 採用分析函數來實現 

2.先介紹常用的rownum

select * from (select row_.*,rownum rn from (select empno,ename,sal from scott.emp where sal>800 order by sal ) row_ where rownum<11)  where rn>5;  

3.使用 rowid分頁(如果查詢裡面有 排序了,在最外面也要排序)

select * from emp where rowid in (select rid from (select rownum rn,rid from (select rowid rid,sal from emp where sal>800 order by sal) where rownum<11) where rn>5) order by sal; //發現不能和group by 使用,有人說是oracle的bug。所以 一般人都用 rownum分組  

4.採用分析函數

select * from (select e.*,row_number() over(order by sal) rk from emp e where e.sal>800) where  rk<11 and rk>5 // 這個 在資料量比較多的時候 速度嚴重下降,所以一般人也不選這個.  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.