Oracle沒有 sqlserver的 top number 功能。只能以期間的形式實現
代碼實現分頁,參數curPage 當前頁、pageSize 每頁行數,計算出起始結束頁碼
int startPage = (curPage - 1) * pageSize + 1;
int endPage = curPage * pageSize;
如:當前第一頁,每頁10行得到 1,10
當前第二頁,每頁10行得到21,20
....
Oracle SQL寫法
取 第一條到第十條數據(索引從1開始),同等於 TOP 10
select *
from (select t.*, rownum rn from sys_table t where rownum <= endPage )
where rn >= startPage
結果如下
select *
from (select t.*, rownum rn from sys_table t where rownum <= 10)
where rn >= 1
錯誤寫法
select *
from (select t.* from sys_users t where rownum <= 10)
where rownum >= 1