Oracle数据库如何解决ORA-04091触发器⼀函数不能读它的问题

2024-11-26 22:52:44
推荐回答(2个)
回答1:

解决ORA-04091触发器/函数不能读它,需用oracle的自治事务。
举例如下:
create or replace trigger TR_U_ID_SYNCH
before update on COMPANY referencing old as old_value
new as new_value
for each row
declare
tId company.id%type;
PRAGMA AUTONOMOUS_TRANSACTION;
begin
if :new_value.U_ID is not null and :new_value.U_ID!=ld_value.U_ID then
select t.t_id into tId from company t where t.id= :new_value.U_ID;
:new_value.P_ID :=:new_value.U_ID;
:new_value.T_ID :=tId;
end if;
COMMIT;
end TR_CO_GB_ID_SYNCH;

回答2:

create or replace trigger tri_insert
before insert on student
for each row
when (new.class=99)
begin
:new.class:=1;
end tri_insert;