CREATE OR REPLACE TRIGGER DTULTATU_PRODRETI
BEFORE INSERT OR UPDATE OR DELETE
ON PRODRETI FOR EACH ROW
BEGIN
   IF INSERTING THEN
      :NEW.DTULTATU := SYSDATE;
   END IF;

   IF UPDATING THEN
      IF (NVL(:OLD.CDTIPORETI,0) <> NVL(:NEW.CDTIPORETI,0)) OR
         (NVL(:OLD.CDPRODRETI,0) <> NVL(:NEW.CDPRODRETI,0)) THEN
         :NEW.DTULTATU := SYSDATE;
      END IF;
   END IF;

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

ALTER TABLE PRODRETI MODIFY DTULTATU DEFAULT SYSDATE
/