今天在写一个触发器的时候,发现在当前表的行级触发器里,对当前表进行查询报一下错误:
ORA-04091: 表 COMPANY 发生了变化, 触发器/函数不能读它。
上网查了一会,解决办法还挺难找,不过还是找到了。在这分享个大家,希望大家能顺利解决这种问题。触发器语句如下:
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;
[color=red]PRAGMA AUTONOMOUS_TRANSACTION;[/color]
begin
if :new_value.U_ID is not null and :new_value.U_ID!= :old_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;
[color=red] COMMIT;[/color]
end TR_CO_GB_ID_SYNCH;
加上红色部分就好了,目前还不知道这样做有什么问题没,如果谁知道有什么隐患的话,还请告知一下,谢谢!
ORA-04091: 表 COMPANY 发生了变化, 触发器/函数不能读它。
上网查了一会,解决办法还挺难找,不过还是找到了。在这分享个大家,希望大家能顺利解决这种问题。触发器语句如下:
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;
[color=red]PRAGMA AUTONOMOUS_TRANSACTION;[/color]
begin
if :new_value.U_ID is not null and :new_value.U_ID!= :old_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;
[color=red] COMMIT;[/color]
end TR_CO_GB_ID_SYNCH;
加上红色部分就好了,目前还不知道这样做有什么问题没,如果谁知道有什么隐患的话,还请告知一下,谢谢!