这个触发器要怎么写?
有两张表如下
JGS表
sjjgid jgid
JGYS表
sjjgid jgid
当JGS表中有记录写入的时候。
比如
insert into jgs(sjjgid,jgid)values(2,3)
把这条记录同时写入JGYS表,并且
select sjjgid into tmp from jgys where jgid=2 (用jgs.sjjgid做为jgys.jgid来搜索jgys.sjjgid)
并把搜索出来的数据也写入jgys表中
insert into jgys(sjjgid,jgid) values(tmp,jgs.jgid)
------解决方案--------------------CREATE OR REPLACE TRIGGER XXX
AFTER insert on JGS
for each row
DECLARE
pragma autonomous_transaction;
tmp number(20, 2);
begin
if inserting then
begin
select sjjgid into tmp from jgys where jgid=2
insert into JGYS (sjjgid,jgid)
values
(:new.sjjgid,
:new.jgid);
insert into JGYS (sjjgid,jgid)
values
(tmp,
:new.jgid);
commit;
end if;
end;
end if;
end;