
CREATE OR REPLACE TRIGGER DTULTATU_LINHAPRODSETOR
BEFORE INSERT OR UPDATE OR DELETE
ON LINHAPRODSETOR FOR EACH ROW

BEGIN
   IF INSERTING THEN
      :NEW.DTULTATU := SYSDATE;
   END IF;
   IF UPDATING THEN
      IF (NVL(:OLD.CDLINHAPROD,0     ) <> NVL(:NEW.CDLINHAPROD,0)   ) OR
         (NVL(:OLD.CDSETOR,0         ) <> NVL(:NEW.CDSETOR,0)       ) OR
         (NVL(:OLD.CDSETORCORRESP,0  ) <> NVL(:NEW.CDSETORCORRESP,0)) THEN
         :NEW.DTULTATU := SYSDATE;
      END IF;
   END IF;
   IF DELETING THEN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
                       VALUES ('LINHAPRODSETOR', '', 'CDFILIAL='||:OLD.CDFILIAL||';CDLINHAPROD='||:OLD.CDLINHAPROD||';CDSETOR='||:OLD.CDSETOR||';', SYSDATE);
   END IF;
END;

/
-- VERSAO --
BEGIN ATUVEROBJ('DTULTATU_LINHAPRODSETOR','6.39.017'); END;
/
