/* @C:\web_509\SQL\end_conv\oracle\01PU_GOPTRGO_DTUTLATU_CALENDORCOPERAC.sql */
CREATE OR REPLACE TRIGGER DTULTATU_CALENDORCOPERAC
BEFORE INSERT OR UPDATE OR DELETE
ON CALENDORCOPERAC FOR EACH ROW

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATU := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.DTINIFASEORCA,TO_DATE('31/12/1899')) <> NVL(:NEW.DTINIFASEORCA,TO_DATE('31/12/1899'))) OR
         (NVL(:OLD.DTFINFASEORCA,TO_DATE('31/12/1899')) <> NVL(:NEW.DTFINFASEORCA,TO_DATE('31/12/1899'))) OR
         (NVL(:OLD.IDPERMCALCJAN,0) <> NVL(:NEW.IDPERMCALCJAN,0)) OR
         (NVL(:OLD.IDPERMCALCFEV,0) <> NVL(:NEW.IDPERMCALCFEV,0)) OR
         (NVL(:OLD.IDPERMCALCMAR,0) <> NVL(:NEW.IDPERMCALCMAR,0)) OR
         (NVL(:OLD.IDPERMCALCABR,0) <> NVL(:NEW.IDPERMCALCABR,0)) OR
         (NVL(:OLD.IDPERMCALCMAI,0) <> NVL(:NEW.IDPERMCALCMAI,0)) OR
         (NVL(:OLD.IDPERMCALCJUN,0) <> NVL(:NEW.IDPERMCALCJUN,0)) OR
         (NVL(:OLD.IDPERMCALCJUL,0) <> NVL(:NEW.IDPERMCALCJUL,0)) OR
         (NVL(:OLD.IDPERMCALCAGO,0) <> NVL(:NEW.IDPERMCALCAGO,0)) OR
         (NVL(:OLD.IDPERMCALCSET,0) <> NVL(:NEW.IDPERMCALCSET,0)) OR
         (NVL(:OLD.IDPERMCALCOUT,0) <> NVL(:NEW.IDPERMCALCOUT,0)) OR
         (NVL(:OLD.IDPERMCALCNOV,0) <> NVL(:NEW.IDPERMCALCNOV,0)) OR
         (NVL(:OLD.IDPERMCALCDEZ,0) <> NVL(:NEW.IDPERMCALCDEZ,0)) THEN

         :NEW.DTULTATU := SYSDATE;
      END IF;

   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('CALENDORCOPERAC', '', 'NRANOORCOPERAC='||:OLD.NRANOORCOPERAC||';'||
                                                      'CDFASEORCOPERAC='||:OLD.CDFASEORCOPERAC||';', SYSDATE);
   END IF;
END;
/

ALTER TABLE CALENDORCOPERAC MODIFY DTULTATU DEFAULT SYSDATE
/

-- VERSAO --
BEGIN ATUVEROBJ('DTULTATU_CALENDORCOPERAC','5.09.000'); END;
/
