1create
orreplace package pck_users as
2 type user_cursor is ref cursor;3
end
pck_users45
create
orreplace
procedure
fenye (
6 tablename in
varchar2, --
表名7 pageindex in
number, --
顯示的頁數
8 pagetotal in
number, --
每頁顯示的條數
9 sortname in
varchar2,--
排序的字段
10 sortdesc in
varchar2,--
公升序還是降序
11 pagecount out number,--
總的頁數
12 totalcount out number, --
總的數量,
13 p_cursor out pck_users.user_cursor, --
返回游標
14 resut_code out number
--狀態碼15)
16is
17--
定義部分
18 v_begin number:=((pageindex*pagetotal)-pagetotal)+
1;--
從那個位置開始查詢
19 v_end number:=pageindex*
pagetotal;
20 v_sql varchar(2000); --
執行的sql語句
21--
執行部分
22begin
23 v_sql:=
'select * from (select t.*,rownum rn from
24(select * from
'|| tablename ||
'order by
'|| sortname||''
||sortdesc ||
') t1 where rownum<=
'|| v_end ||')
25where rn>='||
v_begin ;
26open p_cursor for v_sql;--
開啟游標
27--
查詢總條數
28select
count(*) into totalcount from
tablename;
29--
這樣也行
30/*
31v_sql:='select count(*) into totalcount from '||tablename;
32--執行sql語句
33execute immediate v_sql into totalcount;
34*/
35--
計算總的頁數 ,用mod函式取餘
36if mod(totalcount,pagetotal)=
0then
37 pagecount:=totalcount/
pagetotal;
38else
39 pagecount:=(totalcount/pagetotal)+1;
40endif;
41close p_cursor; --
關閉游標
42 resut_code:=
1; --
成功43
44--
異常部分
45exception
46when other then
47 resut_code:=
0; --
失敗48
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...