CREATE OR REPLACE TRIGGER DTULTATU_FILI
BEFORE INSERT OR UPDATE OR DELETE
ON FILIAL FOR EACH ROW

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATUFILI := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.CDFILIAL,0)       <> NVL(:NEW.CDFILIAL,0))      OR
         (NVL(:OLD.NMFILIAL,0)       <> NVL(:NEW.NMFILIAL,0))      OR
         (NVL(:OLD.CDFILCENTCMP,0)   <> NVL(:NEW.CDFILCENTCMP,0))  OR
         (NVL(:OLD.CDREGIAO,0)       <> NVL(:NEW.CDREGIAO,0))      OR
         (NVL(:OLD.IDCNTRRESC,0)     <> NVL(:NEW.IDCNTRRESC,0))    OR
         (NVL(:OLD.CDEMPRESA,0)      <> NVL(:NEW.CDEMPRESA,0))     OR
         (NVL(:OLD.CDINSCESTA,0)     <> NVL(:NEW.CDINSCESTA,0))    OR
         (NVL(:OLD.CDINSCMUNI,0)     <> NVL(:NEW.CDINSCMUNI,0))    OR
         (NVL(:OLD.CDSEGMER,0)       <> NVL(:NEW.CDSEGMER,0))      OR
         (NVL(:OLD.IDFUNCAOFILI,0)   <> NVL(:NEW.IDFUNCAOFILI,0))  OR
         (NVL(:OLD.CDGRUPOFISC,0)    <> NVL(:NEW.CDGRUPOFISC,0))   OR
         (NVL(:OLD.CDSERIE,0)        <> NVL(:NEW.CDSERIE,0))       OR
         (NVL(:OLD.CDFILIFISC,0)     <> NVL(:NEW.CDFILIFISC,0))    OR
         (NVL(:OLD.NRINSJURFILI,0)   <> NVL(:NEW.NRINSJURFILI,0))  OR
         (NVL(:OLD.IDTPIJURFILI,0)   <> NVL(:NEW.IDTPIJURFILI,0))  OR
         (NVL(:OLD.CDFILCENTPME,0)   <> NVL(:NEW.CDFILCENTPME,0))  OR
         (NVL(:OLD.IDFILCENTPME,0)   <> NVL(:NEW.IDFILCENTPME,0))  OR
         (NVL(:OLD.IDUTILOFFLINE,0)  <> NVL(:NEW.IDUTILOFFLINE,0)) OR
         (NVL(:OLD.NMRAZSOCFILI,0)   <> NVL(:NEW.NMRAZSOCFILI,0))  OR
         (NVL(:OLD.CDFORNAGETERC,0)  <> NVL(:NEW.CDFORNAGETERC,0)) OR
         (NVL(:OLD.IDCUMUPISCOFIL,0) <> NVL(:NEW.IDCUMUPISCOFIL,0)) OR
         (NVL(:OLD.IDENDEMISFIL,0)   <> NVL(:NEW.IDENDEMISFIL,0)) OR
         (NVL(:OLD.IDUTLNFSVENCONS,0) <> NVL(:NEW.IDUTLNFSVENCONS,0)) THEN
		 
         :NEW.DTULTATUFILI := SYSDATE;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('FILIAL', '', 'CDFILIAL='||:OLD.CDFILIAL||';', SYSDATE);
   END IF;
END;
/