← Tutti gli articoli

Italian VAT validation - Validazione della Partita Iva in PLSQL

28 June 2012  ·  PLSQL · Article  ·  517 visite

You can verify the validity of an Italian VAT number.

CREATE OR REPLACE FUNCTION check_pi ( pIva varchar2 )
return integer
is
-- restituisce codice errore
x integer := 0;
y integer := 0;
c integer := 0;
l integer := 0;
z integer := 0;
t integer := 0;
begin
L := length(pIva);
if pIva is NULL then
return 2;
-- argomento nullo
elsif length(pIva) <> 11 then
return 3;
-- lunghezza errata
end if;
DBMS_OUTPUT.PUT_LINE(pIva);
for I in 1..11 loop
c:= TO_NUMBER( substr(pIva, I, 1));
if  REMAINDER(i,2)  = 0 then
y := y + c;
--PARI
if c>=5 then
z := z +1;
end if;
else
x := x + c;
end if;
end loop;
-- DBMS_OUTPUT.PUT_LINE('x=' || to_char(x));
-- DBMS_OUTPUT.PUT_LINE('y=' || to_char(y));
-- DBMS_OUTPUT.PUT_LINE('z=' || to_char(z));
t := (x + (2 * y) + z) ;
if   REMAINDER( t , 10) <>  0 then
return 1;
else
return 0;
end if;
EXCEPTION
WHEN OTHERS
THEN
RETURN -1;
end CHECK_PI;
Si è verificato un errore imprevisto. Ricarica

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.