BEGIN
   DECLARE
      V_MAXADQ VARCHAR2(20);
      V_MAXVALID VARCHAR2(20);
      
    PROCEDURE CORRIGENOVOCODIGO
    AS
    BEGIN
       SELECT MAX(NRADQUIRENTE)
        INTO V_MAXADQ
        FROM ADQUIRENTE;
        
        SELECT MAX(NRVALIDACAOADQ)
        INTO V_MAXVALID
        FROM VALIDACAOADQ;
        
        V_MAXADQ   := LPAD(TO_CHAR(V_MAXADQ), 20, '0');
        V_MAXVALID := LPAD(TO_CHAR(V_MAXVALID), 20, '0');
        
        UPDATE NOVOCODIGO
           SET NRSEQUENCIAL = V_MAXADQ
         WHERE CDCONTADOR = 'ADQUIRENTE';
         
        UPDATE NOVOCODIGO
           SET NRSEQUENCIAL = V_MAXVALID
         WHERE CDCONTADOR = 'VALIDACAOADQ';
    END;
    BEGIN
      CORRIGENOVOCODIGO;
    END;
END;

/