Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/05/2011, 05:10
guardianglorioso
 
Fecha de Ingreso: agosto-2006
Mensajes: 174
Antigüedad: 17 años, 8 meses
Puntos: 2
Respuesta: ORA-04091: mutating, trigger/function may not see it

Buenas,


Efectivamente, ese error sale cuando dentro de un trigger se esta haciendo una operacion sobre la propia tabla sobre la cual se está lanzando dicho disparador.

Una de las soluciones es usar la clausula de TRANSACCIONES AUTONOMAS. Esto es, marcamos el subprograma para que se comporte como transacción diferente a la del proceso principal, llevando el control de COMMIT o ROLLBACK independiente. Como se puede ver en el ejemplo, que es similar a tu caso:


SQL> CREATE OR REPLACE TRIGGER tbi_short
2 BEFORE INSERT
3 ON x_short
4 REFERENCING NEW AS NEW OLD AS OLD
5 FOR EACH ROW
6 declare
7 pragma autonomous_transaction;
8 begin
9 -- if creating a new default then set all other default(s) false
10 if (:new.b_default = -1) then
11 update x_short set b_default = 0 where b_default = -1;
12 commit;
13 end if;
14
15 -- generate pk
16 if :new.pk is null then
17 execute immediate 'select sys_op_guid() from dual ' into :new.pk;
18 end if;
19
20 End;
21 /

Saludos