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.


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;
/
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s