oracle儲存過程實現分頁

2021-06-18 16:19:57 字數 1776 閱讀 2071

建立儲存過程:

--建立存放游標的包--

create or replace package page_package

is --申明游標--

type page_cursor is ref cursor;

end page_package;

--建立查詢所有使用者的過程--

create or replace procedure proc_getalluser(users out page_package.page_cursor)

asbegin

open users for

select * from tuser;

end;

--建立分頁儲存過程--

create or replace procedure proc_page(

tablename in varchar2,--需要查詢的表名--

pagenum in number,--查詢頁碼--

pagesize in number,--每頁條數--

term in varchar,--查詢條件,形如: and name = ? and ......--

datas out page_package.page_cursor,--查詢出來的資料--

maxpagenum out number --最大頁碼--

)is--定義需要執行的sql語句的變數--

v_sql varchar2(1000);

--定義兩個整數變數--

v_begin number:=(pagenum-1)*pagesize+1;

v_end number:=pagenum*pagesize;

--定義最大條數的變數--

v_count number:=0;

begin

--給v_sql賦值--

v_sql := 'select p.* from(select t.*,rownum rn from '||tablename||' t where 1=1 '||term||') p where p.rn between '||v_begin||' and '||v_end;

--執行sql給游標賦值--

open datas for v_sql;

--計算最大頁碼--

v_sql := 'select count(*) from '||tablename||' where 1=1 '||term;

execute immediate v_sql into v_count;

if mod(v_count,pagesize)=0 then

maxpagenum := v_count/pagesize;

else

maxpagenum := v_count/pagesize+1;

end if;

end;

分頁sql:

--分頁的sql--

select p.* from

(select t.*,rownum rn from torganization t) p where p.rn between 2 and 4

使用:

private resultset rs;

private callablestatement cst;

string sql = "";

try

} catch (exception e) finally

oracle 儲存過程實現分頁

1 create or replace package pkg query is23 45 author administrator 6 created 2016 12 8 星期四 10 28 37 7 purpose 用做查詢游標89 10 public type declarations 11 ...

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...