Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Help! Trouble with Triggers
I have a table that can only have a certain number of rows (let's say the max is two rows). I set up a trigger to count the entire table after each insert. The table is initially empty. I issue the same statements in TWO sessions.
insert into test values (1);
insert into test values (2);
After both sessions have completed these two lines, I issued a commit to each. Both commit and leave a total of 4 rows in the table.
How can I make a trigger that will prevent this from happening??
Please email answers to matt_larson_at_jdedwards.com Thanks
create or replace trigger trigger_test
AFTER INSERT on test
DECLARE
v_variable number;
BEGIN
select count(*) into v_variable from test;
if v_variable > 2 then
raise_application_error(-20000,'Too many entries in table');
end if;
END trigger_test;
Received on Thu Dec 18 1997 - 00:00:00 CST