这句话的意思是 你在触发器/函数中使用了被修改的表
比如我的
create or replace trigger A.sync_exam_item_branch_to_b
after insert or delete or update on A.Exam_item_branch
for each row
begin
错误用法
if inserting then
insert into b.tb00b10(id, item_id, dept_id, is_active)
select
t.id,
(select v.id from b.v_tb00b00_vs_advicetype v where v.code = t.item_id and ROWNUM =1) item_id,
(select v.id from b.tb00c00 v where v.code = t.BRANCH_ID) dept_id,
t.STATE is_active -- ,t.*
from A.Exam_item_branch t -- 注意这里,这个表不能被查询
where t.id = :NEW.id;
end if ;
正确用法
.......
if inserting then
insert into b.tb00b10(id, item_id, dept_id, is_active)
select
:new.id,
(select v.id from b.v_tb00b00_vs_advicetype v where v.code = :new.item_id and ROWNUM =1) item_id,
(select v.id from b.tb00c00 v where v.code = :new.BRANCH_ID) dept_id,
:new.STATE is_active
from dual -- 注意 表XX发生了变化,触发器/函数不能读它
where not exists( select 1 from b.tb00b10 b10 where b10.id = :new.id);
end if ;
......
end;
网友评论