Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

newbie question on creating trigger having two conditions

temMar 28 2012 — edited Mar 29 2012
I 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 26 2012
Added on Mar 28 2012
31 comments
2,519 views