CREATE OR REPLACE PROCEDURE GRAVAERROCTBCNC(
   P_ESTABELEC IN NUMBER,
   P_DTINICIAL IN DATE,
   P_DTFINAL IN DATE,
   P_ERRO IN VARCHAR,
   P_SOLUCAO IN VARCHAR,
   P_VISIVEL IN VARCHAR,
   P_NRORG IN NUMBER)
IS
   PRAGMA AUTONOMOUS_TRANSACTION;
   V_COUNT NUMBER;
   V_SEQUENCIAL NUMBER;
   V_TEMP VARCHAR2(20);
BEGIN
  V_COUNT := 0;
  SELECT COUNT(*)
    INTO V_COUNT
    FROM LOGERROCTBCNC
   WHERE DSERRO = P_ERRO
     AND DSSOLUCAO = P_SOLUCAO
     AND NRESTABELEC = P_ESTABELEC
     AND NRORG = P_NRORG;
  IF V_COUNT = 0 THEN
     NOVO_CODIGO_NT('LOGERROCTBCNC', V_TEMP);
     V_SEQUENCIAL := TO_NUMBER(V_TEMP);
     INSERT INTO LOGERROCTBCNC
        (NRLOGERROCTBCNC, NRESTABELEC, DTINICIAL, DTFINAL, DSERRO, DSSOLUCAO, IDVISIVEL, NRORG)
     VALUES
        (V_SEQUENCIAL, P_ESTABELEC, P_DTINICIAL, P_DTFINAL, P_ERRO, P_SOLUCAO, P_VISIVEL, P_NRORG);
  END IF;
  COMMIT;
END;
/

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