CREATE OR REPLACE TRIGGER DTULTATU_TPOP
BEFORE INSERT OR UPDATE OR DELETE
ON TIPOOPERAC FOR EACH ROW

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATUTPOP := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.CDTIPOOPER,0)     <> NVL(:NEW.CDTIPOOPER,0))     OR
         (NVL(:OLD.IDUTCTRLAIDF,0)   <> NVL(:NEW.IDUTCTRLAIDF,0))   OR
         (NVL(:OLD.NMTIPOOPER,0)     <> NVL(:NEW.NMTIPOOPER,0))     OR
         (NVL(:OLD.IDENTRSAIDOP,0)   <> NVL(:NEW.IDENTRSAIDOP,0))   OR
         (NVL(:OLD.IDORIGDESTOP,0)   <> NVL(:NEW.IDORIGDESTOP,0))   OR
         (NVL(:OLD.IDUTILOPER,0)     <> NVL(:NEW.IDUTILOPER,0))     OR
         (NVL(:OLD.IDUTILVENC,0)     <> NVL(:NEW.IDUTILVENC,0))     OR
         (NVL(:OLD.IDGERAVENC,0)     <> NVL(:NEW.IDGERAVENC,0))     OR
         (NVL(:OLD.IDUTILEMISNF,0)   <> NVL(:NEW.IDUTILEMISNF,0))   OR
         (NVL(:OLD.DSTIPOOPEFAT,0)   <> NVL(:NEW.DSTIPOOPEFAT,0))   OR
         (NVL(:OLD.IDOPERDEVONF,0)   <> NVL(:NEW.IDOPERDEVONF,0))   OR
         (NVL(:OLD.IDUTLLISTORI,0)   <> NVL(:NEW.IDUTLLISTORI,0))   OR
         (NVL(:OLD.IDNFORIGOBRI,0)   <> NVL(:NEW.IDNFORIGOBRI,0))   OR
         (NVL(:OLD.DSOPERNFORIG,0)   <> NVL(:NEW.DSOPERNFORIG,0))   OR
         (NVL(:OLD.IDATUESTTPOP,0)   <> NVL(:NEW.IDATUESTTPOP,0))   OR
         (NVL(:OLD.CDGRUPOFISC,0)    <> NVL(:NEW.CDGRUPOFISC,0))    OR
         (NVL(:OLD.IDPERNUMENF,0)    <> NVL(:NEW.IDPERNUMENF,0))    OR
         (NVL(:OLD.IDPERALTDSEM,0)   <> NVL(:NEW.IDPERALTDSEM,0))   OR
         (NVL(:OLD.IDDCORIGRELAC,0)  <> NVL(:NEW.IDDCORIGRELAC,0))  OR
         (NVL(:OLD.IDCONSPARFIS,0)   <> NVL(:NEW.IDCONSPARFIS,0))   OR
         (NVL(:OLD.IDUTGERNFTRAN,0)  <> NVL(:NEW.IDUTGERNFTRAN,0))  OR
         (NVL(:OLD.IDINFCPFCNPJNF,0) <> NVL(:NEW.IDINFCPFCNPJNF,0)) OR
         (NVL(:OLD.CDFORNECEDPADR,0) <> NVL(:NEW.CDFORNECEDPADR,0)) OR
         (NVL(:OLD.DSOPERNFAVISTA,0) <> NVL(:NEW.DSOPERNFAVISTA,0)) OR
         (NVL(:OLD.IDSERIEAUTO,0)    <> NVL(:NEW.IDSERIEAUTO,0))    OR
         (NVL(:OLD.IDCONTABOPER,0)   <> NVL(:NEW.IDCONTABOPER,0))   OR
         (NVL(:OLD.IDTPTRANSNFE,0)   <> NVL(:NEW.IDTPTRANSNFE,0))   OR
         (NVL(:OLD.IDNFPRESTSERV,0)  <> NVL(:NEW.IDNFPRESTSERV,0))  OR
         (NVL(:OLD.IDNFAJUSTE,0)     <> NVL(:NEW.IDNFAJUSTE,0))     OR
         (NVL(:OLD.IDNFESTCANC,0)    <> NVL(:NEW.IDNFESTCANC,0))    OR
         (NVL(:OLD.IDTRATRECBRUTA,0) <> NVL(:NEW.IDTRATRECBRUTA,0)) OR
         (NVL(:OLD.IDUTILOPEROFF,0)  <> NVL(:NEW.IDUTILOPEROFF,0))  OR
         (NVL(:OLD.IDOBINFCSTICMENT,0)  <> NVL(:NEW.IDOBINFCSTICMENT,0)) OR
         (NVL(:OLD.IDOBINFCSTCFOPEN,0)  <> NVL(:NEW.IDOBINFCSTCFOPEN,0)) OR
         (NVL(:OLD.IDOPERDEVOOL,0)      <> NVL(:NEW.IDOPERDEVOOL,0))     OR
         (NVL(:OLD.IDTIPOOPERELE,0)     <> NVL(:NEW.IDTIPOOPERELE,0))    OR
         (NVL(:OLD.IDOBRDTREFFAT,0)     <> NVL(:NEW.IDOBRDTREFFAT,0))    OR
         (NVL(:OLD.IDALTDTREFAPROV,0)   <> NVL(:NEW.IDALTDTREFAPROV,0))  OR
         (NVL(:OLD.IDNFRETIND,0)        <> NVL(:NEW.IDNFRETIND,0))       OR
         (NVL(:OLD.IDOPTRIANGULAR,0)    <> NVL(:NEW.IDOPTRIANGULAR,0))   OR
         (NVL(:OLD.IDENTRTERCEIRO,0)    <> NVL(:NEW.IDENTRTERCEIRO,0))   OR
         (NVL(:OLD.IDREMESSAINDU,0)     <> NVL(:NEW.IDREMESSAINDU,0))    OR
         (NVL(:OLD.IDCONSFISCPROD,0)    <> NVL(:NEW.IDCONSFISCPROD,0))   OR
         (NVL(:OLD.IDUTILNFSE,0)        <> NVL(:NEW.IDUTILNFSE,0))       OR
         (NVL(:OLD.IDBRINDETPOPER,0)    <> NVL(:NEW.IDBRINDETPOPER,0))   OR
		       (NVL(:OLD.IDREARATMANNF,0)     <> NVL(:NEW.IDREARATMANNF,0))    OR
		       (NVL(:OLD.IDNTRANSCREICMS,0)   <> NVL(:NEW.IDNTRANSCREICMS,0))  OR
         (NVL(:OLD.CDTIPOOPERBONIF,0)   <> NVL(:NEW.CDTIPOOPERBONIF,0))THEN
         :NEW.DTULTATUTPOP := SYSDATE;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('TIPOOPERAC', '', 'IDENTRSAIDOP='||:OLD.IDENTRSAIDOP||';CDTIPOOPER='||:OLD.CDTIPOOPER||';', SYSDATE);
   END IF;
END;
/

ALTER TABLE TIPOOPERAC MODIFY DTULTATUTPOP DEFAULT SYSDATE
/