你好,游客 登录 注册 搜索
背景:
阅读新闻

Oracle 分页的三种实现

[日期:2012-08-06] 来源:Linux社区  作者:takeme [字体:大 中 小]

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 // 这个 在数据量比较多的时候 速度严重下降,所以一般人也不选这个.  

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款