续篇:https://www.cnblogs.com/heyang78/p/15336400.html

 

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

相关文章:

  • 2022-02-06
  • 2021-08-29
  • 2022-01-17
  • 2021-06-19
  • 2022-01-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-10
  • 2022-12-23
  • 2021-07-16
  • 2021-05-16
相关资源
相似解决方案