Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create or replace procedure IdentificaSospetti(Anno CONTRIBUENTI.Anno%TYPE , Professione PROFESSIONI.Professione%TYPE) is
- cursor calcoloSpese is
- select CONTRIBUENTI.CF,RedditoIRPEF,Categoria,sum(Importo) as sommaImporto
- from CONTRIBUENTI,SPESE
- where CONTRIBUENTI.Professione=Professione and CONTRIBUENTI.Anno=Anno and SPESE.CF=CONTRIBUENTI.CF
- and to_char(SPESE.DATA,'yyyy')=to_char(Anno,'yyyy')
- group by CONTRIBUENTI.CF,RedditoIRPEF,Categoria
- order by 1;
- coefficiente PROFESSIONI.Coefficiente%TYPE;
- flag boolean:=false;
- CF CONTRIBUENTI.CF%TYPE;
- Reddito CONTRIBUENTI.RedditoIRPEF%TYPE;
- Somma number:=0;
- moltiplicatore number:=0;
- begin
- Select Coefficiente into coefficiente
- From PROFESSIONI
- Where PROFESSIONI.Professione=Professione;
- for tmp in calcoloSpese loop
- if(flag=false) then
- flag:=true;
- CF:=tmp.CF;
- Reddito:=tmp.RedditoIRPEF;
- end if;
- if(CF!=tmp.CF) then
- Somma:=Somma*coefficiente;
- if(Somma>Reddito*1.50) then
- DBMS_OUTPUT.PUT_LINE('Contribuente '||CF||' sospetto');
- end if;
- CF:=tmp.cf;
- Reddito:=tmp.RedditoIRPEF;
- Somma:=0;
- end if;
- if(tmp.Categoria='Casa') then
- moltiplicatore:=0.05;
- elsif (tmp.Categoria='Vacanze')then
- moltiplicatore :=2;
- elsif (tmp.Categoria='Abbigliamento')then
- moltiplicatore :=1.5;
- else
- moltiplicatore :=1;
- end if;
- Somma:=Somma+(tmp.sommaImporto*moltiplicatore);
- end loop;
- EXCEPTION
- when NO_DATA_FOUND then
- DBMS_OUTPUT.PUT_LINE('Professioen non presente');
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement