触发器select 问题
我有表 table1 和 table2 两个表结构是 一样的 字段 id和name, 我需求是 给 table2 建立触发器 执行 insert 语句时 判断 将要插入的数据是否在 table2 里有 如果有 就将数据插入到 table1 中。
这是我写的代码:
create or replace trigger table2_insert
after insert on table2
for each row
declare
v_count := 0;
begin
select count(*) into v_count from table2 where nvl(id,'1')=nvl(:new.id,'1') and nvl(name,'1')=nvl(:new.name,'1') ;
if v_count > 0 then
insert into table1 values(:new.id,:new.name);
end if;
end;
在我执行
insert into table2 values('1','www');
错误:
ora-04091 表system.table2 发生变化,触发器/函数不能读它。
我尝试去除
select count(*) into v_count from table2 where nvl(id,'1')=nvl(:new.id,'1') and nvl(name,'1')=nvl(:new.name,'1') ; 这句
能正常插入。
求大牛指点,我刚学oracle不久