A表
字段一   字段二   字段三
     Q           W             0
     E            R             0
B表
字段四    字段五   字段六
    A              C            0
    G              H           0
当把表A中字段三更新为1,表内容显示如下:
A表
字段一   字段二   字段三
     Q           W             1
     E            R             1
B表
字段四    字段五   字段六
    A              C            0
    G              H           0
    A              C            1
    G              H           1
求大神帮忙。

解决方案 »

  1.   


    SQL> 
    SQL> create table a(c1 varchar(10), c2 varchar(10), c3 int);
    Table created
    SQL> create table b(c1 varchar(10), c2 varchar(10), c3 int);
    Table created
    SQL> create trigger tri_a_up
      2  before update on a
      3  for each row
      4  begin
      5      insert into b values(:new.c1, :new.c2, :new.c3);
      6  end;
      7  /
    Trigger created
    SQL> insert into a values('A','B',0);
    1 row inserted
    SQL> insert into a values('C','D',0);
    1 row inserted
    SQL> update a set c3 = 1 ;
    2 rows updated
    SQL> select * from b;
    C1         C2                                              C3
    ---------- ---------- ---------------------------------------
    A          B                                                1
    C          D                                                1
    SQL> drop table a purge;
    Table dropped
    SQL> drop table b purge;
    Table droppedSQL> 
      

  2.   


    ----建立这个触发器就能满足你的需求
    create or replace trigger trig_T
    before update on A表
    for each row
    begin
      if :New.字段三 = 1 then
        insert into B表
          select 字段四, 字段五, 1 from B表 t where t.字段六 = 0;
      end if;
    end;
      

  3.   


    ----建立这个触发器就能满足你的需求
    create or replace trigger trig_T
    before update on A表
    for each row
    begin
      if :New.字段三 = 1 then
        insert into B表
          select 字段四, 字段五, 1 from B表 t where t.字段六 = 0;
      end if;
    end;
      

  4.   


    CREAT OR REPLACE TRIGGER TRIG_I
    BEFORE UPDATE ON 表A
    DECLARE IVSN NUMBER;
    BEGIN 
    SELECT DISTINCT 字段六 INTO IVSN FROM 表B;
    IF NEW.字段三NOT IN IVSN THEN
    INSERT INTO 表B
    SELECT 字段四,字段五,MAX(字段六)+1 AS 字段六
    FROM 表B
    GROUP BY 字段四,字段五;
    END IF;
    END;
    这么写有问题,麻烦告诉我问题在哪里,初学者实在太笨了。
      

  5.   

    @卖水果的net 不知道怎么用书面语来描述,我觉得好无奈啊