How to make a trigger work after a certain UPDATE

oracletrigger

I would like to know if it's possible to create a trigger on Oracle that is invoked only when a certain UPDATE is done. For example:

UPDATE colors
SET tastes_good = y
WHERE color_name = 'Apple';

should call the trigger, while

UPDATE colors
SET tastes_good = n
WHERE color_name = 'Apple';

should not.

Best Answer

Something like this will suit your needs:

create or replace trigger colors_utrig
after update on colors
for each row
begin
  if :new.tastes_good = 'y'
    then
      -- put your code here
      NULL;
  end if;
end;
/