SET serveroutput on DECLARE rs1 varchar2(255); rs2 varchar2(255); operatore varchar2(15); operatore_donor varchar2(15); dir_out varchar2(255); num NUMBER(5,0); cod varchar2(15); cod1 varchar2(15); desc_olo varchar2(15); totale NUMBER(5,0); tot NUMBER(5,0); file1 UTL_FILE.file_type; count_tot NUMBER(5,0); num1 number(5,0); num2 number(5,0); num3 number(5,0); num4 number(5,0); num5 number(5,0); num6 number(5,0); num7 number(5,0); num8 number(5,0); num9 number(5,0); num10 number(5,0); totale1 NUMBER(5,0):=0; totale2 NUMBER(5,0):=0; totale3 NUMBER(5,0):=0; totale4 NUMBER(5,0):=0; totale5 NUMBER(5,0):=0; totale6 NUMBER(5,0):=0; totale7 NUMBER(5,0):=0; totale8 NUMBER(5,0):=0; totale9 NUMBER(5,0):=0; totale10 NUMBER(5,0):=0; data_inizio date; data_fine date; data date; di date; df date; ut varchar2(20); pippo varchar2(255):='&1'; CURSOR cur_recipient is SELECT desc_olo FROM mnp_olo_report where flag_attivo = 1; Cursor cur_select(operatore varchar2, data_inizio date, data_fine date) is --select nvl(to_char(sum(a.num)),'NULL'), select nvl(sum(a.num),0), a.cod, a.cod1, b.desc_olo from mnp_olo_report b, ( select count(*)num, codice_operatore_recipient cod, codice_operatore_donating cod1 from mnp_gestione_richiesta_porting grp, mnp_mss_cess_porting_in ci, (SELECT desc_olo desc_olo FROM mnp_olo_report where flag_attivo = 1) a where grp.stato in(4,6) and grp.msisdn = ci.msisdn and data_cut_over <> trunc(ci.data_ora_cessazione) and data_cut_over >= trunc(data_inizio) and data_cut_over <= trunc(data_fine) and grp.codice_operatore_donating = a.desc_olo and grp.codice_operatore_recipient = operatore group by codice_operatore_recipient , codice_operatore_donating UNION select count(*)num, codice_operatore_recipient cod, codice_operatore_donating cod1 from mnp_gestione_richiesta_porting grp,(SELECT desc_olo desc_olo FROM mnp_olo_report where flag_attivo = 1) a where grp.stato in(1,3,5) and data_cut_over >= trunc(data_inizio) and data_cut_over <= trunc(data_fine) and grp.codice_operatore_donating = a.desc_olo and grp.codice_operatore_recipient = operatore group by codice_operatore_recipient , codice_operatore_donating,a.desc_olo )a where a.cod1(+) = b.desc_olo and b.flag_attivo = 1 group by a.cod,a.cod1,b.desc_olo order by b.desc_olo; BEGIN if (pippo <> 'nullo')then data_inizio := to_date('&1','dd/mm/yyyy'); data_fine := to_date('&2','dd/mm/yyyy'); dir_out:='&3'; else if (to_char(sysdate, 'DD')<= '15') then data := add_months((trunc(sysdate)), -1); data_inizio := to_date('16/'|| to_char(trunc(data), 'mm/yyyy'),'dd/mm/yyyy'); data_fine := last_day(trunc(data)); else data_inizio := to_date('01/'|| to_char(trunc(sysdate), 'mm/yyyy'), 'dd/mm/yyyy'); data_fine := to_date('15/'|| to_char(trunc(sysdate), 'mm/yyyy'), 'dd/mm/yyyy'); end if; select recipient_out into dir_out from mnp_olo_report where desc_olo = 'MONIT'; end if; file1 := UTL_FILE.fopen (dir_out, 'TIM_TerzaParte_'||to_char(sysdate,'yyyyMMdd')||'.csv', 'w'); BEGIN UTL_FILE.put_line (file1,'Titolo: Non effettuati da TIM in qualita di OLO il giorno del cut_over'); UTL_FILE.put_line (file1,' '); UTL_FILE.put_line (file1,'Periodo dal '|| trunc(data_inizio)|| ' al '|| trunc(data_fine)); UTL_FILE.put_line (file1,' '); UTL_FILE.put_line (file1,'Operatore Terza Parte TIM'); UTL_FILE.put_line (file1,' '); rs1:=''; rs2:=''; totale:=0; tot:=0; OPEN cur_recipient; LOOP FETCH cur_recipient INTO operatore; EXIT WHEN cur_recipient%NOTFOUND; rs1:= rs1 ||';'|| operatore ; END LOOP; CLOSE cur_recipient; rs1:=rs1 ||';'||'TOTALE'; UTL_FILE.put_line (file1,rs1); UTL_FILE.fflush (file1); --UTL_FILE.fclose (file1); exception when others then DBMS_OUTPUT.PUT_LINE(sqlerrm); END; begin rs1:=''; rs2:=''; totale:=0; tot :=0; num1 := 0; num2 := 0; num3 := 0; num4 := 0; num5 := 0; num6 := 0; num7 := 0; num8 := 0; num9 := 0; num10 := 0; OPEN cur_recipient; LOOP FETCH cur_recipient INTO operatore; EXIT WHEN cur_recipient%NOTFOUND; OPEN cur_select(operatore,data_inizio, data_fine); count_tot := 0; totale := 0; tot:=0; LOOP FETCH cur_select INTO num,cod,cod1,desc_olo; EXIT WHEN cur_select%NOTFOUND; --dbms_output.put_line('desc_olo '|| desc_olo); --rs1:= cod1 ||';' || rs1 || ';'|| num ||';'; count_tot := count_tot + 1; rs2 := '' || rs2 || num ||';'; if (count_tot = 1) then num1:= num + num1; tot := num1 + tot; totale1:= totale1 + num1; --dbms_output.put_line('num 1 e...' || num1 || 'num...' || num ||'count_tot'||count_tot ||'operatore cod'|| cod ||'cod1'||cod1); end if; if (count_tot = 2) then num2:= num + num2; tot := num2 + tot; totale2:= totale2 + num2; --dbms_output.put_line('num 2 e...' || num2 || 'num...' || num ||'count_tot'||count_tot); end if; if (count_tot = 3) then num3:= num + num3; tot := num3 + tot; totale3:= totale3 + num3; --dbms_output.put_line('num 3 e...' || num3 || 'num...' || num ||'count_tot'||count_tot); end if; if (count_tot = 4) then num4:= num + num4; --dbms_output.put_line('tot e...' || tot); tot := num4 + tot; totale4:= totale4 + num4; --dbms_output.put_line('num 4 e...' || num4 || 'num...' || num ||'count_tot'||count_tot); end if; if (count_tot = 5) then num5:= num + num5; tot := num5 + tot; totale5:= totale5 + num5; --dbms_output.put_line('num 5 e...' || num5 || 'num...' || num ||'count_tot'||count_tot); end if; if (count_tot = 6) then num6:= num + num6; tot := num6 + tot; totale6:= totale6 + num6; --dbms_output.put_line('num 6 e...' || num6 || 'num...' || num ||'count_tot'||count_tot); end if; if (count_tot = 7) then num7:= num + num7; tot := num7 + tot; totale7:= totale7 + num7; --dbms_output.put_line('num 7 e...' || num7 || 'num...' || num ||'count_tot'||count_tot); end if; if (count_tot = 8) then num8:= num + num8; tot := num8 + tot; totale8:= totale8 + num8; --dbms_output.put_line('num 8 e...' || num8 || 'num...' || num ||'count_tot'||count_tot); end if; if (count_tot = 9) then num9:= num + num9; tot := num9 + tot; totale9:= totale9 + num9; --dbms_output.put_line('num 9 e...' || num9 || 'num...' || num ||'count_tot'||count_tot); end if; if (count_tot = 10) then num10:= num + num10; tot := num10 + tot; totale10:= totale10 + num10; --dbms_output.put_line('num 10 e...' || num10 || 'num...' || num ||'count_tot'||count_tot); end if; END LOOP; CLOSE cur_select; UTL_FILE.put_line (file1,operatore ||';'|| rs2 || tot ||';'); rs2 := ''; tot := 0; num1 := 0; num2 := 0; num3 := 0; num4 := 0; num5 := 0; num6 := 0; num7 := 0; num8 := 0; num9 := 0; num10 := 0; END LOOP; --totale := 0; totale:= totale1+totale2+totale3+totale4+totale5+totale6+totale7+totale8+totale9+totale10; UTL_FILE.put_line (file1,'TOTALE;'|| totale1 || ';'|| totale2 || ';'|| totale3 || ';'|| totale4 || ';'|| totale5 || ';'|| totale ||';'); -- UTL_FILE.put_line (file1, arr(count_tot)); --dbms_output.put_line('ciao fine loop '); CLOSE cur_recipient; --rs1:= rs1; --rs2:= rs2 || totale ||';'; --UTL_FILE.put_line (file1,rs1); --UTL_FILE.put_line (file1,rs2); UTL_FILE.fflush (file1); UTL_FILE.fclose (file1); exception WHEN NO_DATA_FOUND THEN null; when others then DBMS_OUTPUT.PUT_LINE(sqlerrm); END; end; / exit;