
CREATE OR REPLACE TRIGGER DTULTATU_SORTORDERSBYORG
BEFORE INSERT OR UPDATE OR DELETE
ON SORTORDERSBYORG FOR EACH ROW

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

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

/
