Handling mod_user in a table using trigger
642201Jul 12 2011 — edited Jul 13 2011Hi,
I have a table "test" with two columns value and mod_user. Currently the table has a before Update trigger to update the mod_user as system user
Now I have to modify the trigger to satisfy the below criteria
1) In an update statement If I manually set the mod_user, then it should be updated as defined in the update statement.
Eg:
UPDATE test
SET value = 1,
mod_user = 'xyz'
WHERE value = 4;
In the above scenario mod_user should be updated to 'xyz' in the table
2) If I do not mention any set clause for mod_user, then the default windows user should be updated in the table.
UPDATE test
SET value = 1
WHERE value =4;
In the above scenario mod_user should be updated as windows user in the table
The trigger statement I have used does not seem to be working.
CREATE OR REPLACE TRIGGER t_mod_test
BEFORE UPDATE OF value ON test
FOR EACH ROW
BEGIN
:new.mod_user := NVL(SYS_CONTEXT('USERENV','OS_USER'),USER);
END;
Any suggestions on how I can make the scenario working would be highly appreciated.
Thanks in advance
Das