--定义一个包,在包中定义类型test_cursor,是个游标 create or replace package testpackage as type test_cursor is ref cursor; end testpackage; --分页过程 --输入表名,每页显示记录数,当前页 --输出总记录数,总页数,和返回结果 create or replace procedure fenye( tableName in varchar2, --表名 pageTotal in number, --每页条数 pageNow in number, --显示第几页 rowTotal out number, --总共条数 pageCount out number, --总共页数 info out testpackage.test_cursor --详细信息 ) is v_begin number :=(pageNow-1)*pageTotal; v_end number :=pageNow*pageTotal; v_sql varchar2(2000); begin v_sql :='SELECT * FROM '||tableName||' WHERE rowid in ( SELECT rid FROM ( SELECT rownum rn,rid from ( SELECT rowid rid FROM '||tableName||' ) WHERE rownum<='||v_end||' ) WHERE rn>='||v_begin||' );'; open info for v_sql; v_sql:='select count(*) into FROM '||tableName; --执行sql语句 execute immediate v_sql into rowTotal; if mod(rowTotal,pageTotal)=0 then pageCount:=rowTotal/pageTotal; else pageCount:=rowTotal/pageTotal+1; end if; close test_cursor; --关闭游标 end;