create or replace package pck_users as
type user_cursor is ref cursor;
end pck_users
create or replace procedure fenye (
tablename in varchar2, --表名
pageindex in number, --顯示的頁數
pagetotal in number, --每頁顯示的條數
sortname in varchar2,--排序的字段
sortdesc in varchar2,--公升序還是降序
pagecount out number,--總的頁數
totalcount out number, --總的數量,
p_cursor out pck_users.user_cursor, --返回游標
resut_code out number --狀態碼
)is--定義部分
v_begin number:=((pageindex*pagetotal)-pagetotal)+1;--從那個位置開始查詢
v_end number:=pageindex*pagetotal;
v_sql varchar(2000); --執行的sql語句
--執行部分
begin
v_sql:='select * from (select t.*,rownum rn from
(select * from '|| tablename ||' order by '|| sortname||' '||sortdesc ||') t1 where rownum<='|| v_end ||')
where rn>='||v_begin ;
open p_cursor for v_sql;--開啟游標
--查詢總條數
select count(*) into totalcount from tablename;
--這樣也行
/*v_sql:='select count(*) into totalcount from '||tablename;
execute immediate v_sql into totalcount;
*/--計算總的頁數 ,用mod函式取餘
if mod(totalcount,pagetotal)=0 then
pagecount:=totalcount/pagetotal;
else
pagecount:=(totalcount/pagetotal)+1;
end if;
close p_cursor; --關閉游標
resut_code:=1; --成功
--異常部分
exception
when other then
resut_code:=0; --失敗
end;
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...