oracle 存储过程分页模板

  1. create or replace package pck_users as    
  2. type user_cursor is ref cursor;    
  3. end   pck_users  
  4.   
  5. create or replace  procedure fenye (  
  6.         tableName in varchar2, --表名  
  7.         pageIndex in number,  --显示的页数  
  8.         pagetotal in number,  --每页显示的条数  
  9.         sortName in varchar2,--排序的字段  
  10.         sortDesc in varchar2,--升序还是降序  
  11.         pageCount out number,--总的页数  
  12.         totalCount out number, --总的数量,  
  13.         p_cursor out pck_users.user_cursor, --返回游标  
  14.         resut_code out number  --状态码  
  15.         )  
  16. is  
  17. --定义部分  
  18. v_begin number:=((pageIndex*pagetotal)-pagetotal)+1;--从那个位置开始查询  
  19. v_end number:=pageIndex*pagetotal;  
  20. v_sql varchar(2000); --执行的sql语句  
  21. --执行部分  
  22. begin  
  23.     v_sql:='select * from  (select t.*,rownum rn from   
  24.     (select * from '|| tableName ||' order by '|| sortName||' '||sortDesc ||') t1 where rownum<='|| v_end ||')   
  25.     where rn>='||v_begin ;  
  26.     open p_cursor for v_sql;--打开游标  
  27.        --查询总条数  
  28.        select count(*) into totalCount from tableName;  
  29.        --这样也行  
  30.        /*  
  31.         v_sql:='select count(*) into totalCount from '||tableName;  
  32.     execute immediate v_sql into totalCount;  
  33.        */  
  34.        --计算总的页数 ,用mod函数取余  
  35.        if  mod(totalCount,pagetotal)=0 then  
  36.        pageCount:=totalCount/pagetotal;  
  37.     else   
  38.        pageCount:=(totalCount/pagetotal)+1;  
  39.     end if;  
  40.     close   p_cursor; --关闭游标  
  41.     resut_code:=1; --成功  
  42.   
  43. --异常部分  
  44.     exception   
  45.     when other then  
  46.     resut_code:=0; --失败  
  47. end;  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值