選擇表中的某一行記錄:(理解:rownum是oracle系統(tǒng)順序分配為從查詢返回的行的編號(hào))select * from (select rownum a,t.* from te
選擇表中的某一行記錄:(理解:rownum是Oracle系統(tǒng)順序分配為從查詢返回的行的編號(hào))
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;
返回有條件且經(jīng)過排序的某段記錄:
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是在提取記錄就已經(jīng)生成,,它先于排序操作,所以必須使用子查詢先排序。
不能為:
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;
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com