有两个表,分别发test1和test2在插入test1表里会去看看test2表中有没有对应test1的记录要是没有就插入,要是有就统计一下test2中的一字段加上test1中的一个字段加起来修改一下。
我的写法为:
create or replace trigger test_trigger 
before insert on test1
for each row
DECLARE numb number;
ammount number;
begin
select count(*) into numb from test2 where sys_id=:new.sys_id and person_id=:new.person_id
if numb<1 then
insert into test2(day_integral_id,sys_id,person_id,integral_ammount,integral_date,last_modify_time) values(sq_wap_day_integral.nextval,:new.sys_id,:new.person_id,:new.integral_ammount,sysdate,sysdate);
elsif numb==1 then
select integral_ammount into ammount from test2 where sys_id=:new.sys_id and person_id=:new.person_id;
update test2 set integral_ammount=:new.integral_ammount+ammount,last_modify_time=sysdate where sys_id=:new.sys_id and person_id=:new.person_id;
end if;
end;