選擇表中的某一行記錄:(理解: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 * f