在光标项上循环

时间:2017-05-08 10:58:09

标签: oracle loops plsql cursor

我有一个带有声明游标的过程plsql如下:

   CURSOR CUR_MOVIMENTO_MA (myCurXXX VARCHAR2,myCurDateStart timestamp,myCurDateEnd timestamp) IS 
       SELECT ATTR_IMPORTO AS IMP,UID_MOVIMENTO 
       from OMN_V_MOVIMENTO
       WHERE DATE_ACQUISTO BETWEEN myCurDateStart AND myCurDateEnd 
       AND CODE_SOTTOTIPO_MOVIMENTO NOT IN ('0230','0232') 
       AND UID_ABI_ORD_RIC = myCurABI;

begin

     myUID_PRELIEVO_ATM_PARAM := OMR_Y_PRELIEVO_ATM_PARAM.nextval;

     INSERT INTO OMR_V_PRELIEVO_ATM_PARAM(UID_PRELIEVO_ATM_PARAM,CODE_STATO_REPORT_DINAMICO, DATE_INIZIO_ELAB, DATE_FINE_ELAB, ATTR_LOG, FLAG_ATTIVO,ATTR_UID_ABI_RICERCA,DATE_INIZIO_RICERCA, DATE_FINE_RICERCA, CODE_TIPO_REPORT_DINAMICO)
     VALUES(myUID_PRELIEVO_ATM_PARAM, 'R', systimestamp,'' ,'','N',UID_ABI_RICERCA,begin_date, stop_date, TYPE_REPORT);

我正在计算我的日期以创建日期范围:

while stop_date >= my_date or my_date is null loop

  my_date := add_months(my_date,1);
  prev_date := add_months(my_date,-1);

  myChartDate:= to_char(TO_DATE(my_date,'DD-MON-RR'),'MON YYYY', 'nls_date_language=Italian') ;

 P_DATE:=TO_TIMESTAMP(prev_date);
 M_DATE:=TO_TIMESTAMP(my_date);

 SOMMA:=0;

 FOR item IN CUR_MOVIMENTO_MA(XXX, P_DATE, M_DATE)
 LOOP  

   INSERT INTO OMR_V_DETT_PRELIEVO_ATM(UID_DETT_PRELIEVO_ATM,UID_PRELIEVO_ATM_PARAM,DATE_FASCIA, ATTR_PB_UID_MOVIMENTO, ATTR_MA_UID_MOVIMENTO, ATTR_VP_UID_MOVIMENTO) 
   VALUES(OMR_Y_DETT_PRELIEVO_ATM.nextVal,myUID_PRELIEVO_ATM_PARAM,'',item.UID_MOVIMENTO,'','');   
   SOMMA:=SOMMA+item.IMP;
   dbms_output.put_line('SOMMA:'||SOMMA); 

 END LOOP;

 INSERT INTO OMR_V_PRELIEVO_ATM 
 VALUES (OMR_Y_PRELIEVO_ATM.nextval, myUID_PRELIEVO_ATM_PARAM, to_timestamp(my_date), myChartDate, 0, SOMMA, 0); 

end loop;

我通过传递3个元素:XXX和两个时间戳参数来循环进入我的光标。如果日期范围没有项目,则不会运行insert语句。因此,计算到while语句中的其他日期不会传递给游标。我该如何解决这个问题?

0 个答案:

没有答案