//oracle分页存储过程 create or replace proceduce fenye(tableName in varchar2,pageSize in number,pageNow in number,myRowCount out number,myPageCount out number, p_cursor out t1.t---返回记录数的游标 ) is --定义部分 v_sql varchar2(500); v_begin number:=(pageNow-1)*pageSize+1; v_end number:=pageNow*pageSize; begin --开始执行部分 v_sql:='select * from (select t1.*,rownum rn from(select * from '||tableName||') t1 where rownum<='||v_end||')where rn>='||v_begin||'':这表示显示的是第六到第十页的数据 --把游标和sql语句关联 open p_cursor for v_sql; --计算myRowCount和myPageCount v_sql:='select count(*)from '||tableName||''; execute immediate v_sql into myRowCount--执行sql语句并把返回的值赋给myRowCount --计算myPageCount if mod(myRowCount,pageSize)=0 then myPageCount:=myRowCount/pageSize; else myPageCount:=myRowCount/pageSize+1; end if; --关闭游标 close p_cursor; end; |