多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > 數(shù)據(jù)庫 > Oracle > 一次oracle分頁所遇到的問題

一次oracle分頁所遇到的問題

來源:程序員人生   發(fā)布時間:2014-06-08 21:47:07 閱讀次數(shù):4922次

昨天做完項目后讓測試測試了一把,測試說分頁查詢貌似不起作用,翻到第4頁以后,看到的數(shù)據(jù)結(jié)果都是相同的。

當(dāng)時我就覺得很納悶,不可能啊,分頁組件應(yīng)該是好的,咋可能有問題呢。帶著疑問,我打開了自己的ide,在自己的機器上跑了一把,果然有問題。

有問題就要找問題:

首先把2條查詢結(jié)果相同的sql打印出來到數(shù)據(jù)庫中執(zhí)行:

sql1:

select * from (select t.*, rownum rn from (select t_e_id, t_e_name, t_e_tel, t_e_areacode from (select t.eid t_e_id, t.ename t_e_name, t.etel t_e_tel, t.areaid t_e_areacode, t.biz_delete_time, decode(areaid, '0730', '0', '1') orderseq from vr_enterprise t where t.eid not in (select eid from t_biz_erelation)) order by orderseq, biz_delete_time nulls last) t where rownum < 25) where rn >= 19
sql2:

select * from (select t.*, rownum rn from (select t_e_id, t_e_name, t_e_tel, t_e_areacode from (select t.eid t_e_id, t.ename t_e_name, t.etel t_e_tel, t.areaid t_e_areacode, t.biz_delete_time, decode(areaid, '0730', '0', '1') orderseq from vr_enterprise t where t.eid not in (select eid from t_biz_erelation)) order by orderseq, biz_delete_time nulls last) t where rownum <18) where rn >= 12
結(jié)果顯示大多數(shù)行是相同的。

為了找到問題所在,只有先一步一步的精簡化sql,看在哪一步出的問題。

于是找到了,問題出現(xiàn)在where rownum<18的時候數(shù)據(jù)改變了,為什么加了個where條件結(jié)果就會變呢?

表示想不通啊。。。。。

沒辦法,只好baidu了,baidu了半天,都沒人給個解釋啊。。。。。

后來同事說,換個寫法試試,于是改了另一種寫法,如下:

select * from (select t.*, rownum rn from (select t_e_id, t_e_name, t_e_tel, t_e_areacode from (select t.eid t_e_id, t.ename t_e_name, t.etel t_e_tel, t.areaid t_e_areacode, t.biz_delete_time, decode(areaid, '0730', '0', '1') orderseq from vr_enterprise t where t.eid not in (select eid from t_biz_erelation)) order by orderseq, biz_delete_time nulls last) t)m where m.rn >= 1 and m.rn <25
這個方法果然湊效,湊效是湊效,關(guān)鍵是為什么前面那種方法不行呢?抓問題要刨根問底。

看來baidu不行,得換google搜索了。google搜索總是喜歡被china government墻掉,沒辦法,網(wǎng)上只好找了個chrome插件才解決了。

找呀找找呀找,在oracle的ask tom上,tom詳細的介紹了rownum的用法,在這里http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-086197.html

One important thing about using this pagination query is that the ORDER BY statement should order by something unique. If what you are ordering by is not unique, you should add something to the end of the ORDER BY to make it so.

看到這樣一句話,原來用order by的時候還需要增加order by的唯一性,不然rownum就會有問題。哇哈哈哈,太開心了,功夫不費有心人呀,找到問題的癥結(jié)了,當(dāng)然就好解決了。

這權(quán)當(dāng)是一次排錯的經(jīng)歷,特此記錄下來,看來google還是比baidu強大很多啊,以后要好好學(xué)英文,不然遇到問題沒發(fā)解決。

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 伊人成伊人成综合网2222 | 磁力天堂网在线资源www | 一级女人18片毛片免费视频 | 日韩手机在线观看 | 日本一二三区在线视频 | 国产精品乱码一区二区三区 | jizz18欧美18 | free性欧美高清vide0s | 偷拍亚洲欧美 | 香蕉在线精品一区二区 | 欧美另类videovideosex | 亚洲免费精品视频 | japanbabes日本护士18免费 | 成人在线免费小视频 | 亚洲成人小视频 | 中文字幕免费观看 | 日本系列第_1_页_俺去了 | 亚洲综合欧美日韩 | 国产九九热视频 | 欧美笫一页 | 欧美深夜福利 | 欧美人与动性xxxxx杂交 | 欧美激情综合亚洲五月蜜桃 | 一二三四视频免费视频 | 三级国产短视频在线观看 | 日韩一区二三区无 | 综合精品 | 亚洲乱码一区二区三区国产精品 | 欧美aa在线观看 | 91精品福利一区二区 | 91伊人影院 | 久草在线网址 | 国产欧美精品专区一区二区 | 天天在线欧美精品免费看 | 中文字幕中文字幕在线 | 欧美xxxx在线 | 福利在线一区 | 男人天堂亚洲 | 国产精品亚洲片在线不卡 | 国产日韩欧美中文字幕 | 国产视频在线看 |