Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

mutante trigger and autonomous transaction error

527448Apr 9 2007 — edited Apr 9 2007
Hello folks,

I have a problem with a mutating trigger:

I´ve already tried to use an autonomous transaction in this trigger, but, since I have to raise
and exception through RAISE_APPLICATION_ERROR, I get this error message:
ORA-06519: active autonomous transaction detected and rolled back


the structure is the following:

create table AGREGACAO_AGREGACAO
(
GAPR_CD_ID_PAI NUMBER,
GAPR_CD_ID_FILHO NUMBER,
AGAG_DT_INICIO_VALID DATE, -- initial validity date
AGAG_DT_FIM_VALID DATE -- final validity date
);

create or replace trigger T_AGAG
before
INSERT
ON AGREGACAO_AGREGACAO
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
recente_fim_date date;
BEGIN

IF inserting then

begin

-- here an exception is raised.
-- ORA-04091: table xxx is mutating, trigger/function may not see it

select ag.agag_dt_fim_valid
into recente_fim_date
from AGREGACAO_AGREGACAO ag
where ag.gapr_cd_id_pai = :new.gapr_cd_id_pai
and ag.gapr_cd_id_filho = :new.gapr_cd_id_filho
and
ag.agag_dt_inicio_valid =
(select max(ag_max.agag_dt_inicio_valid)
from AGREGACAO_AGREGACAO ag_max
where ag_max.gapr_cd_id_pai = ag.gapr_cd_id_pai
and ag_max.gapr_cd_id_filho = ag.gapr_cd_id_filho
and ag_max.agag_dt_inicio_valid <= :new.agag_dt_inicio_valid);
exception
when NO_DATA_FOUND then
return null; -- no records
end;

if recente_fim_date is null then

RAISE_APPLICATION_ERROR(-20001,
'raise.');

end if;


end if;
END T_AGAG;

I´d like to ask another question: which of these triggers Oracle runs first?
'for each row' or 'table level'?

thanks a lot for any help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 7 2007
Added on Apr 9 2007
2 comments
473 views