I want to be able to see when a specific column was changed. To clarify, I don't want to see when a row was changed. I was able to do that with ROWDEPENDENCIES and triggers with a timestamp. With ROWDEPENDICIES I can see when the whole row was modified last but I specifically want to find out when the a specific column was changed.
To clarify, I want the following table:
id Name Name_modified_on Salary Salary_modified_on
1 Johnson 11.03.16 10:54:27 5000 11.03.16 10:51:27
How do I do that? Thanks. PS: I'm running Oracle 11g.
If you want to find, when a table was last modified like insert,update ,delete, then use the dictionary table dba_tab_modifications.
Oracle converts it to a TIMESTAMP WITH TIME ZONE literal, which means that the session time zone is appended to the TIMESTAMP value. SQL> INSERT INTO table_tstz VALUES(2, TIMESTAMP '2003-01-01 2:00:00'); Insert the same date and time as a TIMESTAMP WITH TIME ZONE literal.
Discussion: To calculate the difference between the timestamps in Oracle, simply subtract the start timestamp from the end timestamp (here: arrival - departure ). The resulting column will be in INTERVAL DAY TO SECOND . The first number you see is the number of whole days that passed from departure to arrival .
Try this code:
Create a table:
CREATE TABLE TEST
(
ID VARCHAR2(2000 BYTE),
NAME VARCHAR2(2000 BYTE),
NAME_MODIFIED_ON DATE DEFAULT sysdate,
SALARY NUMBER(10),
SALARY_MODIFIED_ON DATE DEFAULT sysdate
);
Create a DB trigger:
DECLARE
/******************************************************************************
NAME: COLUMN_UPDATE_TRG
PURPOSE:
REVISIONS:
Ver Date Author Description
--------- ---------- --------------- ------------------------------------
1.0 4.8.2016 Tomaz Kristan 1. Created this trigger.
NOTES:
Automatically available Auto Replace Keywords:
Object Name: COLUMN_UPDATE_TRG
Sysdate: 4.8.2016
Date and Time: 4.8.2016, 14:33:39, and 4.8.2016 14:33:39
Username: (set in TOAD Options, Proc Templates)
Table Name: Z_TEST (set in the "New PL/SQL Object" dialog)
Trigger Options: (set in the "New PL/SQL Object" dialog)
******************************************************************************/
BEGIN
IF UPDATING THEN
IF ( :new.name is not null AND :new.name != :old.name ) THEN
:new.name_modified_on := sysdate;
END IF;
IF ( :new.salary is not null AND :new.salary != :old.salary ) THEN
:new.salary_modified_on := sysdate;
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END COLUMN_UPDATE_TRG;
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