zoukankan      html  css  js  c++  java
  • 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     --执行sql语句
    33     execute immediate v_sql into totalCount;
    34        */
    35        --计算总的页数 ,用mod函数取余
    36        if  mod(totalCount,pagetotal)=0 then
    37        pageCount:=totalCount/pagetotal;
    38     else 
    39        pageCount:=(totalCount/pagetotal)+1;
    40     end if;
    41     close     p_cursor; --关闭游标
    42     resut_code:=1; --成功
    43 
    44 --异常部分
    45     exception 
    46     when other then
    47     resut_code:=0; --失败
    48 end;
  • 相关阅读:
    Codeforces 1045C Hyperspace Highways (看题解) 圆方树
    Codeforces 316E3 线段树 + 斐波那切数列 (看题解)
    Codeforces 803G Periodic RMQ Problem 线段树
    Codeforces 420D Cup Trick 平衡树
    Codeforces 295E Yaroslav and Points 线段树
    Codeforces 196E Opening Portals MST (看题解)
    Codeforces 653F Paper task SA
    Codeforces 542A Place Your Ad Here
    python基础 异常与返回
    mongodb 删除
  • 原文地址:https://www.cnblogs.com/zhiqixue/p/2626525.html
Copyright © 2011-2022 走看看