BEGIN
DECLARE
   V_COUNT NUMBER;
   V_SEQVARCHAR VARCHAR2(50);
   V_SEQUENCIAL NUMBER;

   PROCEDURE INSEREADQUIRENTE(P_CODIGO IN VARCHAR,
                              P_NMADQUIRENTE IN VARCHAR,
                              P_VISIVEL IN VARCHAR)
   AS
   BEGIN
      V_COUNT := 0;
      BEGIN
         SELECT COUNT(A.NRADQUIRENTE)
           INTO V_COUNT
           FROM ADQUIRENTE A
          WHERE A.NMADQUIRENTE = P_NMADQUIRENTE;
      EXCEPTION
         WHEN NO_DATA_FOUND THEN
            V_COUNT := 0;
      END;
      IF V_COUNT = 0 THEN
          /* Insere as ADQUIRENTES (DONAS DAS MAQUININHAS) */
         NOVO_CODIGO_NT('ADQUIRENTE', V_SEQVARCHAR);
         V_SEQUENCIAL := TO_NUMBER(V_SEQVARCHAR);
         INSERT INTO ADQUIRENTE
            (NRADQUIRENTE, CDADQUIRENTE, NMADQUIRENTE,
             VRTAXAADM, VRTOLERANCIA, IDVISIVEL)
         VALUES
            (V_SEQUENCIAL, P_CODIGO, P_NMADQUIRENTE, 0, 0.1, P_VISIVEL);
      END IF;
   END;      
   BEGIN
      INSEREADQUIRENTE('31', 'VALECARD', 'N');
   END;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('INSEREADQVALECARD','6.10.000'); END;
/

