oracle分頁技術

2021-07-16 07:59:38 字數 1035 閱讀 8783

分頁場景在現實生活中很常見,所以我們需要懂得如何利用sql語句實現資料的分頁檢索。

步驟一:建立測試表

create table test (datetime date,str varchar2(32))

/步驟二:插入測試資料

declare

v1 date:=to_date('20160801010000','yyyymmddhh24miss');

begin

for i in 1 .. 30 loop

insert into test values (v1,'hello');

v1:=v1+1/1440;

end loop;

commit;

end;

/步驟三:編寫sql語句實現分頁(核心)(假設一頁顯示3條資料)

1.顯示1~3條資料

select t2.*

from (

select t1.*,rownum rowindex from

(select * from test order by datetime asc) t1

) t2 where t2.rowindex>=1 and t2.rowindex<=(1+3-1)

/2.顯示4~6條資料

select t2.*

from (

select t1.*,rownum rowindex from

(select * from test order by datetime asc) t1

) t2 where t2.rowindex>=4 and t2.rowindex<=(4+3-1)

/3.顯示m~(m+3-1)條資料

select t2.*

from (

select t1.*,rownum rowindex from

(select * from test order by datetime asc) t1

) t2 where t2.rowindex>=m and t2.rowindex<=(m+3-1)

/

Oracle分頁技術詳解

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

Oracle分頁技術詳解

原文出處 分頁查詢語句 select from select a.rownum rn from select from table table name a where rownum 40 where rn 20 最內層的查詢select from table name 表示不進行翻頁的原始查詢語句...

oracle分頁技術講解

編寫任務,資料庫的資料量較大,一次獲得了所有的使用者,造成伺服器的記憶體負擔特別重,便對 做了優化,採用了分頁技術來分批獲得使用者的資料,減少對記憶體的負擔。1 hibernate分頁技術 直接呼叫hibernate介面 public list query int pagesize,int curr...