Mutating Table Exception - A hack
Date: 1995/11/22
Message-ID: <30B3FDF1.39E4_at_ozemail.com.au>#1/1
The problem :
create or replace triggers test_trig
after insert or delete or update on emp
for each row
declare
cursor c1 is
select 'x' from emp where ....;
l_temp varchar2(1);
begin
open c1;
fetch c1 into l_temp;
close c1;
end;
/
You can create this trigger, but will raise ORA-4091 "Mutating table" when
trigger is executed by a triggering statement. The limitation is that, in an
After row / for each row trigger, you cannot select from a table thats
'mutating' ( foreign key tables are included too ).
- Create a database link to the same database. The connect username should be the owner of the table. create database link test_db_link connect to scott identified by tiger using 'SQL net string';
- create or replace package test_pack
as
cursor c1 is
select 'x'
from emp_at_test_db_link;
end test_pack;
/
create or replace trigger test_trig
after insert or update or delete on scott.emp
for each row
declare
L_temp varchar2(1);
begin
open test_pack.c1;
fetch test_pack.c1 into L_temp;
close test_pack.c1;
end;
/
For some reason, if you place the select across the DB link inside the trigger body, the trigger fails to compile. Try referencing the cursor thro' a package and it works fine.
Just another solution - probably impractical to the purists !!
The other solutions to this problems need atleast 3 database triggers, at different levels, and a PL/SQL table.
Any thoughts !!
-- Cheers Sridhar Subramaniam Avion Consulting Services Sydney - Australia Email : ssubrama_at_nibucorp.ccdn.otc.com.au / avion_at_ozemail.com.au Disclaimer : All opinions are truly and just mine.Received on Wed Nov 22 1995 - 00:00:00 CET