저장 프로세스 페이지 나누기

27647 단어 저장 프로세스
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;

좋은 웹페이지 즐겨찾기