Mutating table error in insert trigger
390382Nov 28 2006 — edited Nov 30 2006I have a table where I want to generate the value which would be (maxvalue of that column+1) for a particular id. I have a trigger to generate the value like:
create trigger t
before insert on mytable
begin
select nvl(max(mycolumn),0)+1 into :new.mycolumn from mytable
where id=:new.id;
end;
now, when I execute a statement like
insert into mytable(select column1,column2... from anothertable);
It is giving me this error:
ORA-04091: table mytable is mutating, trigger/function may not see it
I read some posts and tried this workaround but I got the same error. I created a package and a package variable. Then I created 2 insert triggers for the same mytable and in one trigger I populated the value for the package variable and in another one I extracted its value for assigning it to the :new.mycolumn. But I am getting the exact same error.
Any help would be greatly appriciated.