Trigger on Change of Column Value in Oracle

Suppose you need to fire a trigger based on the change of value of a column and then perform some action based on it. You can do it easily like the below.

[sourcecode language="sql"]
CREATE OR REPLACE TRIGGER TEST_TRIGGER
after UPDATE of COLUMNName ON TABLENAME1
for each row
WHEN (
NEW.COLUMNName= '0' and NEW.COLUMNName2='1'
)
BEGIN
if :new.COLUMNName= '0' and :new.COLUMNName2='1' then
update tablename2 set columname3= '2';
end if;
END;
/
[/sourcecode]

 

Category: Database

Tags:

Leave a Reply

Article by: Shadab Mohammad