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

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATU := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.NMFASEORCOPERAC,0) <> NVL(:NEW.NMFASEORCOPERAC,0)) OR
         (NVL(:OLD.NRDIASALERTA,0) <> NVL(:NEW.NRDIASALERTA,0)) OR
         (NVL(:OLD.IDFASECALCORCA,0) <> NVL(:NEW.IDFASECALCORCA,0)) OR
         (NVL(:OLD.IDFASEAPROVORCA,0) <> NVL(:NEW.IDFASEAPROVORCA,0)) THEN
         :NEW.DTULTATU := SYSDATE;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('FASEORCOPERAC', '', 'CDFASEORCOPERAC='||:OLD.CDFASEORCOPERAC||';', SYSDATE);
   END IF;
END;
/

ALTER TABLE FASEORCOPERAC MODIFY DTULTATU DEFAULT SYSDATE
/

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