您的位置:首页 > 数据库 > Oracle

Oracle的分页方法

2016-05-01 00:51 651 查看
  1. 1.根据ROWID来分<!--more-->  
  2.    
  3. select * from t_xiaoxi where rowid in(select rid from (select rownum rn,ridfrom(select rowid rid,cid from   
  4. t_xiaoxi  order by cid desc) where rownum<10000) where rn>9980)order by cid desc;   
  5.    
  6. select * from t_xiaoxi where rowid in(select rid from (select rownum rn,ridfrom(select rowid rid,cid from  
  7. t_xiaoxi  order by cid desc) where rownum<10000) where rn>9980)order by cid desc;  
  8.    
  9. 执行时间0.03秒  
  10. 2.按分析函数来分  
  11.    
  12. select * from (select t.*,row_number() over(order by cid desc) rk from t_xiaoxit) where rk<10000 and rk>9980;   
  13.    
  14. select * from (select t.*,row_number() over(order by cid desc) rk from t_xiaoxit) where rk<10000 and rk>9980;  
  15.    
  16. 执行时间1.01秒  
  17. 3.按ROWNUM来分  
  18.    
  19. select * from(select t.*,rownum rn from(select * from t_xiaoxi order by ciddesc) t where rownum<10000) where   
  20. rn>9980;   
  21.    
  22. select * from(select t.*,rownum rn from(select * < 24a2b /span>from t_xiaoxi order by ciddesc) t where rownum<10000) where  
  23. rn>9980;  
  24.    
  25. 执行时间0.1秒  
  26. 其中t_xiaoxi为表名称,cid为表的关键字段,取按CID降序排序后的第9981-9999条记录,t_xiaoxi表有70000多条记录  
  27. 个人感觉1的效率最好,3次之,2最差    
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: