是这样的:
我有两个表:tableA、tableB。
我现在想建立一个触发器:
要求是这样:在insert A 表之后更新B表中的相应字段值。
比如:我插入A表记录的时候要记录3个字段的值,bid、createdate、aaa
然后随之更新B表中的主键是bid的aaa字段值为createdate。再比如:插入A表的记录是 bbb、2008-12-10、aaa(此为B表中字段名)
那么B中我想更新bbb记录的aaa(aaa是B表中的字段名字)字段内容为2008-12-10

解决方案 »

  1.   


    create or replace trriger tr_test after insert on tableA
    REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
    begin
        update tableB set aaa=:new.createdate where bbb=:new.bid;
    end;
      

  2.   


    create or replace trigger tr_test after insert on tableA
    REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
    begin
        update tableB set aaa=:new.createdate where bbb=:new.bid;
    end;
    不好意思~刚才有点错误
      

  3.   

    create or replace trigger tri_test
     before insert on tableA
     referencing new as new_value
     for each row
    begin
     update tableB 
        set aaa = :new_value.createdate  --aaa是date类型吗,如果不是则用to_char转换下。
      where bid = :bid; 
    end;
    /
      

  4.   

    这里的aaa也是可变的,要怎么处理呢?
    也就是B表里面的属性不只是aaa,还有其他名称
      

  5.   

    A表:
    id    bid    createdate    subb
    1      b-1    2008-12-10    aaa
    2     b-232   2008-12-11    bbb
    B表:
    bid       aaa          bbb
    b-1    2008-12-10   2008-11-1
    b-2    2008-12-14   2008-12-11原来数据是上述那样,
    现在如果我插入A表中这样一条数据
    3    b-2    2009-1-1   aaa
    那么我B表中的数据要求修改为
    b-2    2009-1-1    2008-12-11(也就是说只修改了字段aaa的值)
    如果我A表中插入的数据是这样:
    3    b-2    2009-1-1   bbb
    则我B表中的数据就要这样:
    b-2    2008-12-14    2009-1-1(也就是说只修改了字段bbb的值)
      

  6.   

    有点复杂了~~不知道这样行不行,你试验一下create or replace trigger tr_test after insert on tableA
    REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
    begin
        if :new.subb='aaa' then 
        update tableB set aaa=:new.createdate where bbb=:new.bid
        else
        update tableB set bbb=:new.createdate where bbb=:new.bid;end;
      

  7.   


    create or replace trigger tr_test after insert on tableA
    REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
    begin
        if :new.subb='aaa' then 
        update tableB set aaa=:new.createdate where bbb=:new.bid
        else
        update tableB set bbb=:new.createdate where bbb=:new.bid;
        end if;end;
      

  8.   

    楼上的兄弟,能简单帮我解释一下
    REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW
    是什么意思吗?
    我对这个不了解,谢谢!
      

  9.   

     FOR EACH ROW 是对每一行的意思;
    OLD AS OLD NEW AS NEW  as 后面相当于起个别名,老的数据(old)就叫old,新插入的数据(new)就叫new;
    你想叫别的名称也可以