Oracle
 sql >> Datenbank >  >> RDS >> Oracle

Gibt es einen automatischen Änderungszeitstempeltyp für Oracle-Spalten?

Ziemlich sicher, dass Sie dies mit einem Trigger in Oracle tun müssen:

create or replace TRIGGER parkedorder_tbiur
   BEFORE INSERT OR UPDATE
   ON parkedorder
   REFERENCING OLD AS old_row NEW AS new_row
   FOR EACH ROW
BEGIN
   IF INSERTING
   THEN
      IF :new_row.ID IS NULL
      THEN
         SELECT parkedorder_seq.NEXTVAL
           INTO :new_row.ID
           FROM DUAL;
      END IF;
   END IF;

   IF    :new_row.lastupdated <> SYSDATE
      OR :new_row.lastupdated IS NULL
   THEN
      SELECT sysdate
        INTO :new_row.lastupdated
        FROM DUAL;
   END IF;

   SELECT SYS_CONTEXT ( 'USERENV', 'OS_USER' )
     INTO :new_row.lastupdatedby
     FROM DUAL;
END;