Is there a way to create a timestamp column in Oracle that automatically stores a timestamp of when the record has changed ?
Introduction to Oracle TIMESTAMP data typeThe TIMESTAMP data type allows you to store date and time data including year, month, day, hour, minute and second. In addition, it stores the fractional seconds, which is not stored by the DATE data type.
Oracle introduced TIMESTAMP data type in 9i version. It allows to store date time with fraction of seconds. By default format of TIMESTAMP is 'YYYY-MM-DD HH24:MI:SS. FF'.
Insert the same date and time as a TIMESTAMP literal. SQL> INSERT INTO table_ts VALUES(2, TIMESTAMP '2003-01-01 2:00:00'); Insert the same date and time as a TIMESTAMP WITH TIME ZONE literal. Oracle converts it to a TIMESTAMP value, which means that the time zone information is dropped.
Finally, you can change the default DATE format of Oracle from "DD-MON-YY" to something you like by issuing the following command in sqlplus: alter session set NLS_DATE_FORMAT='<my_format>'; The change is only valid for the current sqlplus session.
Pretty sure you have to do this with a trigger in Oracle:
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With