create or replace trigger tg_a after insert on a for each row declare v_count number; cursor cur(v_id in varchar2) is select * from b where id=v_id for update; begin select count(1) into v_count from b where id=:new.bid; if v_count=0 then insert into b values(:new.bid,:new.img,null,null); return; end if; for c1 in cur(:new.bid) loop if c1.img2 is null then update b set img2=:new.img where current of cur; else update b set img3=:new.img where current of cur; end if; end loop; end;
after insert on a
for each row
declare
v_count number;
cursor cur(v_id in varchar2) is
select * from b where id=v_id for update;
begin
select count(1) into v_count from b where id=:new.bid;
if v_count=0 then
insert into b values(:new.bid,:new.img,null,null);
return;
end if;
for c1 in cur(:new.bid) loop
if c1.img2 is null then
update b set img2=:new.img where current of cur;
else
update b set img3=:new.img where current of cur;
end if;
end loop;
end;