1 要把rowid來分
select * from t_xiaoxi where rowid in(select rid from select rownum rn,rid from (select rowid rid,cid from t_xiaoxi order by cid desc) where rownum<10000) where rn>9980) order by cid desc;
2 按分析函式來分
select * from (select t.*,row_number() over(order by cid desc) rk from t_xiaoxi t )where rk<100000 and rk>9980;
3 按rownum來分。
select * from (select t.* rownum rn from (select * from t_xiaoxi order by cid desc)t where rownum<10000) where rn>9980;
效率1>3>2
create or replace package "ea_pak_pageselect" as
type resultdata is ref cursor;
procedure sp_page(p_pagesize int, --每頁記錄數
p_pageno int, --當前頁碼,從 1 開始
p_sqlselect varchar2, --查詢語句,含排序部分
p_sqlcount varchar2, --獲取記錄總數的查詢語句
p_outrecordcount out int,--返回總記錄數
p_outcursor out resultdata);
end;
create or replace package body "ea_pak_pageselect" as
procedure sp_page(p_pagesize int, --每頁記錄數
p_pageno int, --當前頁碼,從 1 開始
p_sqlselect varchar2, --查詢語句,含排序部分
p_sqlcount varchar2, --獲取記錄總數的查詢語句
p_outrecordcount out int,--返回總記錄數
p_outcursor out resultdata)
as v_sql varchar2(3000);
v_count int;
v_heirownum int;
v_lowrownum int;
begin ----取記錄總數
execute immediate p_sqlcount into v_count;
p_outrecordcount := v_count; ----執行分頁查詢
v_heirownum := p_pageno * p_pagesize;
v_lowrownum := v_heirownum - p_pagesize +1;
v_sql := 'select * from (select a.*, rownum rn from ('|| p_sqlselect ||') a where rownum <= '|| to_char(v_heirownum) ||') b where rn >= '|| to_char(v_lowrownum); --注意對rownum別名的使用,第一次直接用rownum,第二次一定要用別名rn
open p_outcursor for v_sql;
end sp_page;
end;
ORACLE分頁查詢
單錶分頁 start num 起始行號 end num 截止行號 select t.from select s.rownum rn from table s where rownum end num t where rn start num 多表分頁 select from select temp....
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 from select from select from select from product order by id asc where rownum 5 2 1 order by id desc where rownum 5 1 1表示一頁 5表示...