Files
gateway-mnp-dbc/dbcmnpsrc/FE/mnpapp/script/dbUpDate/KitLuglio12/bonifica_cessazione_fase2.sql
2024-05-13 12:54:14 +02:00

45 lines
1.4 KiB
MySQL

set serveroutput on size 10000
spool bonifica_cessazione_fase2.log
declare
-- Local variables here
v_result number;
v_id_richiesta mnp_gestione_richiesta_cess.id_richiesta%type;
v_data mnp_gestione_richiesta_cess.dataricezionerichiesta%type;
v_processo char(1);
begin
for r_cess in
( select *
from mnp_gestione_richiesta_cess t
where t.stato in (91,96,99)
)
loop
-- verifica dell'ultimo processo legato al MSISDN da cessare
v_result := f_trova_ultimo_processo(r_cess.msisdn, v_id_richiesta, v_data, v_processo);
-- aggiornamento dello stato ad ANNULLATA
if v_result = 0 and v_data > r_cess.dataricezionerichiesta then
-- inserimento nello storico
insert INTO MNP_STORICO_CESS (ID_PROG,NOME_FILE,DATA_I_O,STATO_DA,STATO_A, TIPO_FILE,I_O,DATA_LAVORAZIONE,ID_RICHIESTA)
select SEQ_MNP_STORICO_CESS.nextval,'bonifica',sysdate,r_cess.stato,7,7,1,TRUNC(SYSDATE),ID_RICHIESTA
from MNP_GESTIONE_RICHIESTA_CESS where id_richiesta = r_cess.id_richiesta;
update mnp_gestione_richiesta_cess t
set t.stato = 7
where t.id_richiesta = r_cess.id_richiesta;
dbms_output.put_line('Aggiornato lo stato ad ANNULATA per la richiesta '|| r_cess.id_richiesta);
elsif v_result > 0 then
dbms_output.put_line('Errore nella verifica dell''ultimo processo per la richiesta '||r_cess.id_richiesta);
end if;
end loop;
end;
/
commit;
spool off