108 lines
3.4 KiB
SQL
108 lines
3.4 KiB
SQL
--L'indicatore riporta giornalmente il tempo medio impiegato per il
|
|
--passaggio di stato da "Acquisita" ad "Inviata" (verso Donating)
|
|
--delle richieste MNP Recipient di tipo Business.
|
|
--Il tempo medio calcolato è suddiviso per:
|
|
--Operatore Donating.
|
|
--Sono prodotti prodotti tanti record riportanti ognuno il tempo medio calcolato
|
|
--per ogni diverso valore di Operatore Donating.
|
|
--Il dato è calcolato giornalmente per le richieste che nella giornata di
|
|
--rilevazione sono state inviate.
|
|
--Per cui se nella giornata di rilevazione non esistono richieste che sono state
|
|
--inviate il dato non viene rilevato.
|
|
--Il record però è prodotto anche in questo caso associando all'indicatore
|
|
--il valore '-' (trattino).
|
|
--Nel calcolo dei tempi di passaggio di stato sono presi in considerazione solo i giorni lavorativi.
|
|
SET serveroutput on
|
|
|
|
DECLARE
|
|
|
|
data_acq date;
|
|
data_prc date;
|
|
giorni_diff number(10):=0;
|
|
i number(10):=0;
|
|
media varchar2(10):=0;
|
|
somma number(10):=0;
|
|
data_val date;
|
|
file1 UTL_FILE.file_type;
|
|
freq varchar2(255):='&1';
|
|
operatore varchar2(4);
|
|
|
|
cursor cur_operatore is
|
|
select desc_olo from mnp_olo
|
|
where flag_terze_parti=1;
|
|
|
|
cursor cur_date is
|
|
select trunc(a.data_lavorazione),trunc(b.data_lavorazione)
|
|
from mnp_storico_richiesta_rec a,mnp_storico_richiesta_rec b, mnp_gestione_richiesta_rec c
|
|
where a.stato_a=2
|
|
and b.stato_a=4
|
|
and b.data_lavorazione>=trunc(sysdate)
|
|
and b.data_lavorazione<=trunc(sysdate+1)-1/86400
|
|
and a.id_richiesta=b.id_richiesta
|
|
and b.id_richiesta=c.id_richiesta
|
|
and a.data_lavorazione<=b.data_lavorazione
|
|
and b.stato_a!=b.stato_da
|
|
and c.codice_operatore_donating=operatore
|
|
and c.tipo_cliente='BU';
|
|
|
|
cursor cur_giorni_diff is
|
|
select count(*)-1
|
|
from s_dim_tempo a
|
|
where a.data between data_acq and data_prc
|
|
and a.tip_gio not in ('P','F');
|
|
|
|
BEGIN
|
|
|
|
dbms_output.put_line('apro il file ' || 'MNP' || '.' || to_char(sysdate,'yyyyMMdd'));
|
|
file1 := UTL_FILE.fopen('&2','MNP' || '.' || to_char(sysdate,'yyyyMMdd'),'a');
|
|
|
|
open cur_operatore;
|
|
loop
|
|
fetch cur_operatore into operatore;
|
|
exit when cur_operatore%notfound;
|
|
|
|
--calcolo la media
|
|
open cur_date;
|
|
i:=0;
|
|
somma:=0;
|
|
media:='-';
|
|
data_val:=sysdate;
|
|
loop
|
|
|
|
fetch cur_date into data_acq, data_prc;
|
|
exit when cur_date%notfound;
|
|
|
|
open cur_giorni_diff;
|
|
fetch cur_giorni_diff into giorni_diff;
|
|
|
|
somma:= somma + giorni_diff;
|
|
i:=i+1;
|
|
|
|
close cur_giorni_diff;
|
|
end loop;--fine calcolo media per operatore
|
|
close cur_date;
|
|
if(i!=0) then
|
|
media:=to_char(trunc(somma/i,2));
|
|
if((somma/i > 0) and (somma/i < 1))
|
|
then
|
|
media:= '0'|| media;
|
|
end if;
|
|
end if;
|
|
|
|
UTL_FILE.put_line(file1,'SRBUACQ16'||';'||operatore||';'||media||';'
|
|
||freq||';'||'&3'|| ';'
|
|
||to_char(data_val,'yyyymmdd')||';'||to_char(data_val,'hh24:mi:ss') ||';'
|
|
||to_char(sysdate,'yyyymmdd')||';'||to_char(sysdate,'hh24:mi:ss') ||';'
|
|
||'0'||';'||operatore||';;');
|
|
end loop;
|
|
close cur_operatore;
|
|
|
|
UTL_FILE.fflush(file1);
|
|
UTL_FILE.fclose(file1);
|
|
dbms_output.put_line('chiudo il file ' || 'MNP' || '.' || to_char(sysdate,'yyyyMMdd'));
|
|
exception
|
|
when others then
|
|
DBMS_OUTPUT.PUT_LINE(sqlerrm);
|
|
end;
|
|
/
|
|
exit |