CREATE OR REPLACE TRIGGER GRAVA_CDCONTCTBL_LANCCUSTO
BEFORE INSERT
ON LANCCCUSTO FOR EACH ROW
DECLARE
   V_CDCONTCTBL VARCHAR(20);
BEGIN
   IF INSERTING THEN
      BEGIN
         SELECT MAX(CDCONTCTBL) AS CDCONTCTBL
           INTO V_CDCONTCTBL
           FROM LANCCONT
          WHERE CDEMPRESA  = :NEW.CDEMPRESA
            AND NRLANCCONT = :NEW.NRLANCCONT
            AND NRSEQLANC  = :NEW.NRSEQLANC;
      EXCEPTION
         WHEN NO_DATA_FOUND THEN
           V_CDCONTCTBL := NULL;
      END;
      :NEW.CDCONTCTBL := V_CDCONTCTBL;
   END IF;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('GRAVA_CDCONTCTBL_LANCCUSTO','5.30.000'); END;
/