[code]create or replace package curspkg as
type refcursortype 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 refcursortype);
end;[/code]
[code]create or replace package body curspkg is
procedure sp_page(p_pagesize int, --每頁記錄數
p_pageno int, --當前頁碼,從 1 開始
p_sqlselect varchar2, --查詢語句,含排序部分
p_sqlcount varchar2, --獲取記錄總數的查詢語句
p_outrecordcount out int, --返回總記錄數
p_outcursor out refcursortype) is
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;[/code]
[code]sqlstr = "select id,from_userid,to_userid,to_char(adddate,'yyyy-mm-dd hh24:mm:ss') as adddate,content,isread,state,from_username,to_username,title from vw_tdata_inquire";
sqlstrcount = "select count(*) from vw_tdata_inquire";
opendb();
string sql = "";
callablestatement proc = conn.preparecall(sql);
proc.setint(1, p_pagesize); //每頁數量
proc.setint(2, p_pageno); //頁碼
proc.setstring(3, sqlstr); //取資料的sql
proc.setstring(4, sqlstrcount); //取資料個數的sql
proc.registeroutparameter(5, oracle.jdbc.oracletypes.integer); //輸出資料行數
proc.registeroutparameter(6, oracle.jdbc.oracletypes.cursor); //輸出游標記錄集
proc.execute();
rowscount = ( (oraclecallablestatement) proc).getint(5); //總行數
rs = (resultset)proc.getobject(6); //結果集
[/code][url]
分頁儲存過程 分頁儲存過程
分頁儲存過程 alter proc dbo p pageshow pagesize int,每頁大小 currentpage int out,當前頁 housename nvarchar 50 房產名稱 totalcount int out,總記錄數 totalpage int out 總頁數 as...
分頁儲存過程
create proc p sobigo percentpage tblname varchar 255 t category 表名 strgetfields varchar 1000 需要返回的列 fldname varchar 255 排序的欄位名 pagesize int 10,頁尺寸 pag...
分頁儲存過程
create procedure pro select pageindex int,pagesize int as select student.sno,student.sname,student.s grade.math,grade.physics,grade.huaxue,grade.chine...