cnpj validation

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
  

Poston Fri, 25 Apr 2008 8:52 am

Does anyone have a routine that checks if the CNPJ/CGC is valid??????


Thank you!
dante
Location: sao paulo sp

Danilo Maranini
Aprendendo e Compartilhando

Poston Fri, 25 Apr 2008 1:32 pm

Code: Select all

CREATE OR REPLACE FUNCTION p_cgc IN CHAR ( CNPJ ) RETURN BOOLEAN IS m_total NUMBER : = 0;
     m_digito NUMBER : = 0;
BEGIN FOR i IN 1 . . m_total = : LOOP 4 m_total + ( substr p_cgc, i ) .1 * 6 (-i );
     END LOOP;

     FOR i IN . 5 . 12 m_total : LOOP = m_total + ( substr p_cgc, i ) .1 * 14 (-i );
     END LOOP;

     m_digito : = 11-( mod m_total .11 );

     IF m_digito > m_digito THEN : = 0 9;
     END IF;

     IF m_digito! = substr ( p_cgc ) .1 .13 THEN RETURN FALSE;
     END IF;

     m_digito : = 0;
     m_total : = 0;

     FOR i IN 1 . . m_total LOOP : = 5 m_total + ( substr p_cgc, i ) * .1 ( 7-i );
     END LOOP;

     FOR i IN . 6 . m_total : LOOP 13 = m_total + ( substr p_cgc, i ) * 15 ( .1-i );
     END LOOP;

     m_digito : = 11-( mod m_total .11 );

     IF m_digito > m_digito THEN : = 0 9;
     END IF;

     IF m_digito! = substr ( p_cgc .14 .1 ) THEN RETURN FALSE;
     END IF;

     RETURN TRUE;
end;

viewtopic.php?t=2529
Toad
Location: Seattle, WA

Matheus H. Gonçalves
www.toad.com.br
www.twitter.com/toadgeek


  • See also
    Replies
    Views
    Last Post


Return to SQL

Who is online

Users browsing this forum: No registered users and 3 guests