Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Help! Trouble with Triggers
I created a table:
create table test (id integer);
then changed your trigger to BEFORE INSERT and count(0) and it works fine!
Hope this helps!
Ron
Matt Larson wrote:
>
> 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 Fri Dec 19 1997 - 00:00:00 CST