SHARE
TWEET

codigo_barcelos_cnpj

a guest Oct 10th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DROP FUNCTION fc_valida_cnpj;
  2.  
  3. SET SERVEROUTPUT ON;
  4.  
  5. ACCEPT p_cnpj PROMPT 'Preencha seu CNPJ';
  6.  
  7. DECLARE
  8.     v_cnpj      VARCHAR2(250) := &p_cnpj;
  9.     v_total    NUMBER(20) := 0;
  10.     v_dig   NUMBER(20) := 0;
  11. BEGIN
  12.     FOR i IN 1..4 LOOP v_total := v_total + SUBSTR(v_cnpj, i, 1) * ( 6 - i );
  13.     END LOOP;
  14.  
  15.     FOR i IN 5..12 LOOP v_total := v_total + SUBSTR(v_cnpj, i, 1) * ( 14 - i );
  16.     END LOOP;
  17.  
  18.     v_dig := 11 - MOD(v_total, 11);
  19.     IF v_dig > 9 THEN
  20.         v_dig := 0;
  21.     END IF;
  22.     IF v_dig != SUBSTR(v_cnpj, 13, 1) THEN
  23.         DBMS_OUTPUT.put_line('CNPJ Invalido');
  24.     END IF;
  25.  
  26.     v_dig := 0;
  27.     v_total := 0;
  28.     FOR i IN 1..5 LOOP v_total := v_total + SUBSTR(v_cnpj, i, 1) * ( 7 - i );
  29.     END LOOP;
  30.  
  31.     FOR i IN 6..13 LOOP v_total := v_total + SUBSTR(v_cnpj, i, 1) * ( 15 - i );
  32.     END LOOP;
  33.  
  34.     v_dig := 11 - MOD(v_total, 11);
  35.     IF v_dig > 9 THEN
  36.         v_dig := 0;
  37.     END IF;
  38.     IF v_dig != SUBSTR(v_cnpj, 14, 1) THEN
  39.         DBMS_OUTPUT.put_line('CNPJ Invalido');
  40.     ELSE
  41.         DBMS_OUTPUT.put_line('CNPJ Valido');
  42.     END IF;
  43.  
  44. END;
  45. /
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top