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

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATU := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.IDACESSOCALC,0) <> NVL(:NEW.IDACESSOCALC,0)) OR
         (NVL(:OLD.IDACESSOAPROV,0) <> NVL(:NEW.IDACESSOAPROV,0)) THEN
         :NEW.DTULTATU := SYSDATE;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('FILIALOPEROP', :OLD.CDFILIAL, 'CDFILIAL='||:OLD.CDFILIAL||';'||
                                                              'CDGRUPGERENTEOP='||:OLD.CDGRUPGERENTEOP||';'||
                                                              'CDOPERADOR='||:OLD.CDOPERADOR||';', SYSDATE);
   END IF;
END;
/

ALTER TABLE FILIALOPEROP MODIFY DTULTATU DEFAULT SYSDATE
/

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