SQL code:
CREATE OR REPLACE PROCEDURE p_page (
p_sqlcount IN VARCHAR2, -- 记录数sql语句
p_sql IN VARCHAR2, -- 结果集sql语句
p_startpage IN INT, --起始页号
p_pagenum IN INT, --每页记录数
r_count OUT INT, --总记录数
r_cursor OUT sys_refcursor -- 结果集
)
IS
v_start INT;
v_end INT;
v_sql VARCHAR2 (2000);
BEGIN
v_start := (p_startpage - 1) * p_pagenum + 1;
v_end := v_start + p_pagenum - 1;
EXECUTE IMMEDIATE p_sqlcount
INTO r_count;
v_sql :=
'SELECT * '
|| ' from (select t1.*, ROWNUM r '
|| ' from ('
|| p_sql
|| ' ) t1 where rownum <='
|| TO_CHAR (v_end)
|| ') t2 where r >='
|| TO_CHAR (v_start);
OPEN r_cursor FOR v_sql;
EXCEPTION
WHEN OTHERS
THEN
RAISE;
END p_page;
/
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wzy0623/archive/2007/08/14/1742788.aspx
在pl/sql中测试该存储过程:
参数输入如下:
p_sqlcount select * from jtglpt_t_dm_b
p_sql select * from jtglpt_t_dm_b