ITPub博客

首页 > 数据库 > Oracle > oracle分页的处理

oracle分页的处理

原创 Oracle 作者:wenhual43 时间:2013-12-02 18:25:53 0 删除 编辑
有2种写法。今天学会一种新的。
先说下我们业务里的分页,取第20到第30行记录
select z.*
  from (select p.*, rownum rn
          from (select n.* from test n order by user_id) p where rn<=30) z
 where rn >= 20
   and rn <= 30

这种写法用了3个select,嵌套了2个select;

今天看到一种新的写法
select *
  from (select n.*, row_number() over(order by user_id) rn from test n)
 where rn>= 20
   and rn<= 30
这种写法2个select搞定,好像要简洁一些。row_number() over(order by columnname) rn 这种排序函数以后可以尝试用一下。



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25027760/viewspace-1061892/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: MAXPIECESIZE理解
请登录后发表评论 登录
全部评论

注册时间:2011-08-03

  • 博文量
    32
  • 访问量
    130412