create or replace trigger tgname after insert on A for each row declare v_count number; begin select count(1) into v_count from B where b.d=:new.a and b.f=:new.c; if v_count=0 then --不存在,则插入对应的a,b,c到def insert into B(d,e,f) values (:new.a,new:b,:new.c); else update B set e=e+:new.b where b.d=:new.a and b.f=:new.c; end if; end; /
改进一下,对空值进行处理: create or replace trigger tgname after insert on A for each row declare v_count number; begin select count(1) into v_count from B where b.d=:new.a and b.f=:new.c; if v_count=0 then --不存在,则插入对应的a,b,c到def insert into B(d,e,f) values (:new.a,new:b,:new.c); else update B set e=nvl(e,0)+nvl(:new.b,0) where b.d=:new.a and b.f=:new.c; end if; end; /
after insert on A
for each row
declare
v_count number;
begin
select count(1) into v_count from B where b.d=:new.a and b.f=:new.c;
if v_count=0 then --不存在,则插入对应的a,b,c到def
insert into B(d,e,f) values (:new.a,new:b,:new.c);
else
update B set e=e+:new.b where b.d=:new.a and b.f=:new.c;
end if;
end;
/
create or replace trigger tgname
after insert on A
for each row
declare
v_count number;
begin
select count(1) into v_count from B where b.d=:new.a and b.f=:new.c;
if v_count=0 then --不存在,则插入对应的a,b,c到def
insert into B(d,e,f) values (:new.a,new:b,:new.c);
else
update B set e=nvl(e,0)+nvl(:new.b,0) where b.d=:new.a and b.f=:new.c;
end if;
end;
/