1.首先在oracle中建儲存過程,儲存過程名庫 procedure prc_query
create or replace procedure prc_query
(p_tablename in varchar2, --表名
p_strwhere in varchar2, --查詢條件
p_ordercolumn in varchar2, --排序的列
p_orderstyle in varchar2, --排序方式
p_curpage in out number, --當前頁
p_pagesize in out number, --每頁顯示記錄條數
p_totalrecords out number, --總記錄數
p_totalpages out number, --總頁數
v_cur out pkg_query.cur_query) --返回的結果集
isv_sql varchar2(1000) := ''; --sql語句
v_startrecord number(4); --開始顯示的記錄條數
v_endrecord number(4); --結束顯示的記錄條數
begin
--記錄中總記錄條數
v_sql := 'select to_number(count(*)) from ' || p_tablename || ' where 1=1';
if p_strwhere is not null or p_strwhere <> '' then
v_sql := v_sql || p_strwhere;
end if;
execute immediate v_sql into p_totalrecords;
--驗證頁面記錄大小
if p_pagesize < 0 then
p_pagesize := 0;
end if;
--根據頁大小計算總頁數
if mod(p_totalrecords,p_pagesize) = 0 then
p_totalpages := p_totalrecords / p_pagesize;
else
p_totalpages := p_totalrecords / p_pagesize + 1;
end if;
--驗證頁號
if p_curpage < 1 then
p_curpage := 1;
end if;
if p_curpage > p_totalpages then
p_curpage := p_totalpages;
end if;
--實現分頁查詢
v_startrecord := (p_curpage - 1) * p_pagesize + 1;
v_endrecord := p_curpage * p_pagesize;
v_sql := 'select * from (select a.*, rownum r from ' ||
'(select * from ' || p_tablename;
if p_strwhere is not null or p_strwhere <> '' then
v_sql := v_sql || ' where 1=1' || p_strwhere;
end if;
if p_ordercolumn is not null or p_ordercolumn <> '' then
v_sql := v_sql || ' order by ' || p_ordercolumn || ' ' || p_orderstyle;
end if;
v_sql := v_sql || ') a where rownum <= ' || v_endrecord || ') b where r >= '
|| v_startrecord;
dbms_output.put_line(v_sql);
open v_cur for v_sql;
end prc_query;
2.在資料層中呼叫儲存過程,返回乙個datatable及二個引數,datatable儲存資料,curpage為當前頁碼(儲存過程會根據傳入的數值查詢資料,返回datatable。),pagecount為總頁數, recordcount為資料總條數
public class paging
}3。表現層呼叫方法quickpage
oracle分頁儲存過程
page slide procedure author robert.c time 2006.11.17 create or replace procedure tablepage select v page size int,the size of a page of list v current...
Oracle分頁儲存過程
第一步要先建立包 create or replace package pkg query is type cur query is ref cursor procedure met down query m tablename in varchar2,表名 m strwhere in varchar...
Oracle分頁儲存過程
第一步要先建立包 create or replace package pkg query is type cur query is ref cursor procedure met down query m tablename in varchar2,表名 m strwhere in varchar...