• oracle高效分页存储过程(百万数据级)


    create or replace procedure Pager(
    page in number,--数据页数,从1开始
    pageSize in number,--每页大小
    tableName nvarchar2,--表名
    strWhere nvarchar2,--where条件
    Orderby nvarchar2,
    numCount out number,--总记录数
    v_cur out pkg_query.cur_query) is
    
    strSql varchar2(2000);--获取数据的sql语句
    pageCount number;--该条件下记录页数
    startIndex number;--开始记录
    endIndex number;--结束记录
    
    --作者:王东升
    --时间:2010年1月8日14:54:32
    --分页获取数据
    
    begin
      strSql:='select count(1) from '||tableName;
      if strWhere is not null or strWhere<>'' then 
         strSql:=strSql||' where '||strWhere;
      end if;  
      EXECUTE IMMEDIATE strSql INTO numCount;
      --计算数据记录开始和结束
      pageCount:=numCount/pageSize+1;
      startIndex:=(page-1)*pageSize+1;
      endIndex:=page*pageSize;
      
      strSql:='select rownum ro, t.* from '||tableName||' t';  
      strSql:=strSql||' where rownum<='||endIndex;
      
      if strWhere is not null or strWhere<>'' then 
         strSql:=strSql||' and '||strWhere;
      end if;
      
      if  Orderby is not null or Orderby<>'' then 
         strSql:=strSql||' order by '||Orderby;
      end if;
      
      strSql:='select * from ('||strSql||') where ro >='||startIndex;  
      DBMS_OUTPUT.put_line(strSql);
    
      OPEN v_cur FOR strSql; 
    end Pager;
  • 相关阅读:
    党史回顾+十九大习思想+中国历史事件+地理+航天史及古代天文历法
    国际组织
    生活-常识-物理
    生物
    数量题目总结-利润排列组合
    数量题目总结-工程最值集合
    考公错题记录表
    个人向简历介绍
    数据库操作大全
    团队博客作业-技术规格说明书
  • 原文地址:https://www.cnblogs.com/star8521/p/4978704.html
Copyright © 2020-2023  润新知