熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

oracle中rownum對排序的影響及解決方法

2013-11-13 16:16:57  來源: Oracle 

   標准的rownum分頁查詢使用方法

  select *
      from (select c* rownum rn from content c)
     where rn >=
       and rn <=

   但是如果 加上order by addtime 排序則數據顯示不正確

  select *
      from (select c* rownum rn from content c order by addtime)
     where rn >=
       and rn <=

  解決方法再加一層查詢則可以解決

  select *
      from (select rownum rn t*
              from (select title addtime from content order by addtime desc) t)
     where rn >=
       and rn <=

  如果要考慮到效率的問題上面的還可以優化成(主要兩者區別)

  select *
      from (select rownum rn t*
              from (select title addtime from content order by addtime desc) t
             where rownum <= )
     where rn >=


From:http://tw.wingwit.com/Article/program/Oracle/201311/18078.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.