CREATE OR REPLACE TRIGGER ATUA_ESTOQ_CAPALOTE
AFTER DELETE
ON CAPALOTE FOR EACH ROW
BEGIN
    UPDATE ITLANCTOEST
       SET CDEMPITCTB  = NULL,
           CDLOTEITCTB = NULL,
           NRLOTEITCTB = NULL,
           NRSEQITCTB  = NULL
     WHERE IDTIPOMOVI  = '3'
       AND CDEMPITCTB  = :OLD.CDEMPRESA
       AND CDLOTEITCTB = :OLD.CDLOTE;

    UPDATE APRCUSTOP
       SET CDEMPRCTBOP = NULL,
           CDLOTECTBOP = NULL
     WHERE CDEMPRCTBOP = :OLD.CDEMPRESA
       AND CDLOTECTBOP = :OLD.CDLOTE;
    UPDATE ITLANCTOEST
     SET CDEMPITCTB  = NULL,
         CDLOTEITCTB = NULL,
         NRLOTEITCTB = NULL,
         NRSEQITCTB  = NULL
   WHERE CDEMPITCTB  = :OLD.CDEMPRESA
     AND CDLOTEITCTB = :OLD.CDLOTE;
END;
/
-- VERSAO --
BEGIN ATUVEROBJ('ATUA_ESTOQ_CAPALOTE','5.85.000'); END;
/


