ORALCE rownum 案例解說

來源:互聯網
上載者:User
選擇表中的某一行記錄:(理解:rownum是oracle系統順序分配為從查詢返回的行的編號)select * from (select rownum a,t.* from testtab t) where a=2;select * from (select rownum a,t.* from testtab t) where a=3;select * from (select rownum a,t.* from testtab t) where a=4;不能為:select * from (select rownum,t.* from testtab t) where rownum=2;或select * from testtab where rownum=2;返回多行記錄:select * from testtab where rownum<=10;返回某段記錄:(如取記錄表中4-10行)select * from (select rownum no,testtab.* from testtab where rownum<=10) where no>=4;返回有條件且經過排序的某段記錄:select rownum num1,tt.* from (select rownum num,t.* from (select EcodeInfo.* from EcodeInfo where a=1 order by ecode desc) t) tt where num>19 and rownum<20> 以為oracle是先提取記錄再排序的,而oracle的rownum是在提取記錄就已經產生,它先於排序操作,所以必須使用子查詢先排序。不能為:select * from tsettab where rownum>10;返回最後一行記錄:select * from (select rownum a,t.* from testtab t) where a=(select count(*) from testtab);返回最後N行記錄:select * from (select rownum a,t.* from testtab t) where a=(select count(*)-N from testtab); ---------------- select   *   from   adminrole   where   rownum<=4  minus     select   *   from   adminrole   where   rownum<2> select * from   (select rownum row_id ,b.* from (select a.* from sorttable a order by sortid)b)   where row_id between 5 and 9; 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.