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函數。