A表中有ID,BID,img三个字段;
B表中有ID,Img1,Img2,Img3三个字段;
每当A表记录插入的时候,则将值同步到B中,效果如下图:A表
ID  BID  img
1   b1   a.jpg
2   b1   b.jpg
3   b1   c.jpg
4   b2   aa.jpg
B表ID   Img1     Img2     Img3
b1   a.jpg    b.jpg    c.jpg
b2   aa.jpg或者请各位提供更加方便的解决方案。。谢谢!!

解决方案 »

  1.   

    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;