[Oracle] Oracle中和MySql的limit對應的方法


MySql很貼心,有個限制范圍查詢的limit函數,用起來也很方便,SQL不用嵌套。如下:

select id,name,age,cdate as ctime from emp order by id limit #{start},#{size}

老舊的Oracle用rownum也可以實現類似的功能,只是需要嵌套SQL,用起來不方便,具體如下:

select

        *

from

          (select

                      rownum no,id,name,age,createdtime as ctime

           from tb01

           where rownum<=10

           order by id) tbTmp

where no>4

這樣把5,6,7,8,9,10六條記錄都取出來了。

整句是這樣的:

select * from (select rownum no,id,name,age,createdtime as ctime from tb01 where rownum<=10 order by id) tbTmp where no>4

或者:

select * from (select rownum no,id,name,age,createdtime as ctime from tb01 where rownum<=10 order by id) where no>4

 

Oracle這種方式,還是稍顯別扭,希望在其新版本能順應民心加入limit函數。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM