zoukankan      html  css  js  c++  java
  • 存储过程分页

    create or replace function dlmis.fcBSGetRecDetailListEx(iEventTypeID   integer, --案卷类型
                                                            iRegionType    integer, --区域类型 1-市区级别 2-街道级别
                                                            iRegionID      integer, --区域标识
                                                            iRoadID        integer, --道路标识
                                                            iQueryType     integer, --执法类型 1-执法人员 2-执法小组
                                                            iQueryID       integer, --执法标识
                                                            sBeginDate     varchar2, --开始日期
                                                            sEndDate       varchar2, --结束日期
                                                            iCurPage       integer, --当前页
                                                            iPerPageCount  integer, --每页记录数
                                                            iTotalCount    out integer, --一共多少条记录
                                                            curRecInfoList out dlsys.pkdual.AnyCursor, --查询结果集
                                                            sErrorDesc     out varchar2
                                                            ) return integer is
        /**
        功能: 根据案件类型等条件获取案件列表 (1- 2-)
        版本: 监督指挥系统(大屏幕V2)
        参数: iRegionType :   1-市区级别 2-街道级别
        
              返回值为0表示成功,-1为失败,>0为提示
        作者:liul,2015-03-29
        **/
      DEBUG_BEGIN_TIME     number;
      DEBUG_END_TIME       number;
      sSql                 varchar2(20000);
      sWhereSql            varchar2(2000);
      --sCommonSql           varchar2(4000);
      sRsSql               varchar2(8000);
      iFirst               integer;
      iLast                integer;
      iResult integer;
    begin
        DEBUG_BEGIN_TIME := dbms_utility.get_time;
        iResult          := 0;
         if iRegionType is null then
          iResult    := 1;
          sErrorDesc := '案卷类型不可为空';
          return iResult;
        end if;
        if iRegionType is null then
          iResult    := 1;
          sErrorDesc := '区域类型不可为空';
          return iResult;
        end if;
        if iQueryType is null then
          iResult    := 1;
          sErrorDesc := '执法类型不可为空';
          return iResult;
        end if;
       sSql := 'select a.MISSIONID, a.MISSIONCODE, a.MISSIONTYPEID, a.CREATETIME, a.STARTDATE, a.ENDDATE, a.TITLE, a.CONTENT,
         a.OPERATORID, a.VALIDFLAG, a.VALIDTIME, a.DELETEFLAG, a.DELETETIME, a.MODIFYTIME, a.MODIFYHUMANID, a.PUBLISHFLAG, 
         b.MissionTypeName, c.LawCheckTime, c.PartName, c.PartHead, c.PartPhone, c.PartCode, c.RoadName, c.CoordinateX, 
         c.CoordinateY, c.Address, c.RecDesc, c.HumanIDOne, c.HumanIDTwo,d.PatrolName from dlmis.toLCMission a, dlmis.toDicLCMissionType b, dlmis.toLCRec c,dlsys.tcPatrol d
         where a.missiontypeid = b.missiontypeid and a.missionid = c.missionid and c.HumanIDOne=d.PatrolID';
         
         --处理区域条件
         if iRegionType =1 then
           sWhereSql := ' and c.DistrictID=' || iRegionID ;
         elsif iRegionType =2 then
           sWhereSql := ' and c.StreetID=' || iRegionID ;
         end if;
         
         --处理道路条件
         if iRoadID is not null then
           --sWhereSql := sWhereSql || (' and c.RoadID='|| iRoadID) ;
           sWhereSql := sWhereSql;
         end if;
         
         --处理执法类型条件
         if iQueryType =1 then --执法人
            sWhereSql := sWhereSql || ' and c.HumanIDOne='|| iQueryID;
         elsif iQueryType =2 then --执法小组
            sWhereSql := sWhereSql || ' and d.PatrolTeamId='|| iQueryID;
         end if;
         
         --处理时间
         if sBeginDate is not null then
           sWhereSql := sWhereSql || ' and  c.LawCheckTime >= to_date(''' || sBeginDate || ''',''yyyy-mm-dd'')';
         end if;
         if sEndDate is not null then
           sWhereSql := sWhereSql || ' and c.LawCheckTime < to_date(''' || sEndDate || ''',''yyyy-mm-dd'')+1 ';
         end if;
         
         sSql := sSql||sWhereSql;
    
          --返回
          --error
          --plog.error(sSql);
          
          --分页
          sRsSql := 'select count(1)  from  (' || sSql || ') ';
          dbms_output.put_line('sSql:' || sSql);
          execute immediate sRsSql
            into iTotalCount;
          iFirst := 1;
          iLast  := iTotalCount;
          if iCurPage is not null and iPerPageCount is not null then
            iFirst := iPerPageCount * (iCurPage - 1) + 1;
            iLast  := iPerPageCount * iCurPage;
          end if;
          sRsSql := ' select * from (select rownum as rn, MISSIONID,MISSIONCODE,MISSIONTYPEID,CREATETIME,STARTDATE,ENDDATE,TITLE,CONTENT,OPERATORID,VALIDFLAG,VALIDTIME,DELETEFLAG,DELETETIME,MODIFYTIME,MODIFYHUMANID,PUBLISHFLAG,MissionTypeName,LawCheckTime,PartName,PartHead,PartPhone,PartCode,RoadName,CoordinateX,CoordinateY,Address,RecDesc,HumanIDOne,PatrolName,HumanIDTwo  from (' || sSql ||
                    ' )) where  rn >= ' || iFirst || ' and rn <= ' || iLast;
          --error
          --plog.error(sRsSql);
          
          --返回结果集
          if iTotalCount > 0 then
            open curRecInfoList for sRsSql;
          else
            open curRecInfoList for
              select * from dual where 1 = 2;
          end if;
          commit;
          DEBUG_END_TIME := dbms_utility.get_time;
          if DEBUG_END_TIME - DEBUG_BEGIN_TIME > 100 then
            plog.info('根据案件类型等条件获取案件列表{耗时=' || (DEBUG_END_TIME - DEBUG_BEGIN_TIME) ||
                      '}{iEventTypeID=' || iEventTypeID || '}{iRegionType=' ||
                      iRegionType || '}{iRegionID=' || iRegionID || '}{iRoadID=' ||
                      iRoadID || '}{iQueryType=' || iQueryType || '}{iQueryID=' ||
                      iQueryID || '}{sBeginDate=' || sBeginDate ||
                      '}{sEndDate=' || sEndDate || '}{iCurPage=' || iCurPage ||
                      '}{iPerPageCount=' || iPerPageCount || '}');
          end if;
          
          return iResult;
    exception
      when others then
        null;
        rollback;
        plog.error('根据案件类型等条件获取案件列表{耗时=' || (DEBUG_END_TIME - DEBUG_BEGIN_TIME) ||
                  '}{iEventTypeID=' || iEventTypeID || '}{iRegionType=' ||
                  iRegionType || '}{iRegionID=' || iRegionID || '}{iRoadID=' ||
                  iRoadID || '}{iQueryType=' || iQueryType || '}{iQueryID=' ||
                  iQueryID || '}{sBeginDate=' || sBeginDate ||
                  '}{sEndDate=' || sEndDate || '}{iCurPage=' || iCurPage ||
                  '}{iPerPageCount=' || iPerPageCount || '}');
        sErrorDesc := '根据案件类型等条件获取案件列表失败。' || SQLERRM(SQLCODE);
        iResult    := -1;
        return iResult;
    end fcBSGetRecDetailListEx;
    --分页
    llsql := ***;
    sRsSql := 'select count(1) from (' || sSql || ') '; 
    dbms_output.put_line('sSql:' || sSql);
    execute immediate sRsSql into iTotalCount;
    iFirst := 1;
    iLast := iTotalCount;
    if iCurPage is not null and iPerPageCount is not null then
    iFirst := iPerPageCount * (iCurPage - 1) + 1;
    iLast := iPerPageCount * iCurPage; end if;
    sRsSql := ' select * from ('|| llsql ||' from (' || sSql || ' )) where rn >= ' || iFirst || ' and rn <= ' || iLast;
  • 相关阅读:
    【unity3d游戏开发之基础篇】unity3d射线的原理用法以及一个利用射线实现简单拾取的小例子
    【unity3d游戏开发之疑难杂症】Unity3d工程如何与MonoDevelop工具进行调试
    【unity3d游戏开发之疑难杂症】解决Unity3d脚本支持中文问题
    cocos2d 中添加显示文字的三种方式(CCLabelTTF 、CCLabelBMFont 和CCLabelAtlas)
    xcode连不上ipad的原因
    【unity3d游戏开发之疑难杂症】Error while importing package: Couldn't decompress package
    AS3 event flow 事件冒泡机制 以及 stopImmediatePropagation() stopPropagation()用法
    【unity3d游戏开发之基础篇】利用射线实现鼠标控制角色转向和移动(角色移动一)
    Asp.net Session认识加强Session究竟是如何存储你知道吗?
    Windows 7下VS2008无法调试2.0.50727.4952版本mscorlib.dll的解决办法
  • 原文地址:https://www.cnblogs.com/superjt/p/4376642.html
Copyright © 2011-2022 走看看