没有数据插入M表,可能是条件不满足吧 你可以一个一个排查 看看哪个if没有走 if inserting then open c1; fetch c1 into cur_c1; --该处用dbms_output.put_line把cur_c1.name输出,看看值是什么 if cur_c1.name='UUU' then open c2; loop fetch c2 into cur_c2; --该处输出c2查出了多少行 如果没有数据 直接就exit了 当然不往M表写记录 exit when c2%notfound; insert into M values( sysdate,:new.id, cur_c2.id) ; end loop; close c2; -- else ...暂不实行; end if; close c1; end if;
你可以一个一个排查 看看哪个if没有走
if inserting then
open c1;
fetch c1 into cur_c1;
--该处用dbms_output.put_line把cur_c1.name输出,看看值是什么
if cur_c1.name='UUU' then
open c2;
loop
fetch c2 into cur_c2;
--该处输出c2查出了多少行 如果没有数据 直接就exit了 当然不往M表写记录
exit when c2%notfound;
insert into M values( sysdate,:new.id, cur_c2.id) ;
end loop;
close c2;
-- else ...暂不实行;
end if;
close c1;
end if;
--trigger里用cursor,这样的用法确定没错就行,数据我保证能够查询出来。能确认用法做是没有错的吗?
--但是,cursor c1中我取出来的值确实是‘UUU’,为什么if条件不成立?
cur_c2 c2%rowtype;
不知道你为什么这么定义
感觉定义成varchar2完全可以啊
fetch c1.name into cur_c1;
if cur_c1='UUU' then
open c2;