oracle分頁查詢語句

2021-07-31 15:12:09 字數 898 閱讀 8758

oracle分頁查詢語句

select logtime,userno,labcode,primarykey,operatetype,ishaier,logdetail from(select a.*, rownum r from(select * from log) a where rownum < "+(start+length)+")b where r >="+start;

start為開始記錄,length為長度,代表的含義為:查詢從start開始,length條記錄。

mysql中有limit關鍵字,在oracle中並不支援limit,但oracle支援rownum,在分頁查詢時,可以借助rownum來實現。

1、返回5-10行的資料

select * from log t where rownum <10 minus select * from log t where rownum<5

但注意不能這麼寫

select * from log t where rownum <10

and rownum >5

因為oracle並不認為這是正確的條件

2.返回5-10行的資料,這種方式更常用在oracle的分頁查詢中

select * from

(select a.*, rownum r

from

(select *

from log

) awhere rownum <= 10

) bwhere r >=5

select * from(select a.*, rownum r from(select * from log) a where rownum <= 12)b where r >=9

Oracle分頁查詢語句

oracle的分頁查詢語句基本上可以按照本文給出的格式來進行套用。分頁查詢格式 select from select a.rownum rn from select from table name a where rownum 40 where rn 21 其中最內層的查詢select from t...

Oracle分頁查詢語句

分頁查詢格式 select from select a.rownum rn from select from table name a where rownum 40 where rn 21 其中最內層的查詢select from table name表示不進行翻頁的原始查詢語句。rownum 40...

Oracle分頁查詢語句

分頁查詢格式 select from select a.rownum rn from select from table name a where rownum 40 where rn 21 其中最內層的查詢select from table name表示不進行翻頁的原始查詢語句。rownum 40...