1.資料表結構
表名authoring
欄位authoringid number primary key,
name varchar(50) not null,
startdate date
2.分頁:以startdate逆序分頁
select *
from (select a.*, row_number() over(order by a.startdate desc) rownumber
from authoring a) tmp
where tmp.rownumber between 1 and 5;
select *
from (select tmp.*, rownum rownumber
from (select a.* from authoring a order by startdate desc) tmp) rslt
where rslt.rownumber between 1 and 5;
注: order by 是對where過濾之後的結果在快取內進行order,
根據rownum的原理,order之前rownum的值已經確定,
所以分頁時需先order by 然後再取rownum的值
select *
from (select tmp.*, rownum rownumber
from (select a.* from authoring a order by startdate desc) tmp
where rownum <= 5) rslt
where rslt.rownumber >= 1;
select tmp.*
from (select a.* from authoring a order by startdate desc, authoringid) tmp
where rownum <= 6;
(第6條記錄的authoringid=1076328)
select tmp.*
from (
select a.startdate, a.authoringid, a.name
from authoring a
where a.startdate < (select a.startdate from authoring a where a.authoringid = 1076328)
union
select a.startdate, a.authoringid, a.name
from authoring a w
here a.startdate = (select a.startdate from authoring a where a.authoringid = 1076328) and a.authoringid >= 1076328
order by startdate desc, authoringid
) tmp
where rownum <= 6;
oracle 分頁方法
基本分頁方法如下 select from select a.rownum rn from select from tablename a where rownum pagenum 1 pagesize pagesize where rn pagenum 1 pagesize 上面是乙個單錶查詢分頁方...
oracle分頁顯示方法
一 使用rownum分頁顯示方式 方式1 select from select rownum r,a.from b i exch info a where rownum 10 where r 5 方式2 select from select rownum r,a.from b i exch info...
oracle分頁快速實現方法
資料量很大的查詢一定要加分頁,否則嚴重的話甚至會導致資料庫直接掛了 public string getpagesql string originalsql,int pageidx rownum 和rowid 都是偽列,但是兩者的根本是不同的。rownum 是根據sql 查詢出的結果給每行分配乙個邏輯...