newbie question on creating trigger having two conditions
temMar 28 2012 — edited Mar 29 2012I have a table in Oracle 11.2 with two columns, both of "number" data type:
colA
colB
The table always has one row, and only one row (the values in this row are essentially flags). I need a trigger that fires when
(1) colA = 1, and
(2) colB > 0
I've never written a trigger before, but I've come up with two potential methods:
Method 1:
CREATE OR REPLACE TRIGGER my_trigger
AFTER UPDATE OF col1 ON my_table
FOR EACH ROW
WHEN (new.col1 = 1) and (new.col2 > 0)
BEGIN
-- do something here
END;
Method 2:
CREATE OR REPLACE TRIGGER my_trigger
AFTER UPDATE OF col1 ON my_table
BEGIN
if (new.col1 = 1) and (new.col2 > 0) then
-- do something here
end if;
END;
I'm not sure if either of these are syntactically correct. Appreciate any comments on the best approach.