有一个表的status字段,如果update成1则insert into table1
如果update成9则insert into table2
这样的功能该如何实现,本人是触发器方面的新手
望指教,谢谢

解决方案 »

  1.   

    if 什么情况下 update 成 1 then
          insert into table1 select ... ;
    elsif 什么情况下 update 成 2 then
          insert into table2 select ... ;
    else
         两种情况外,还想干什么不?;
    end if;
     
      

  2.   


    create or replace trigger upd_tg 
    after update of status on tt
    for each row
    begin
      if :new.status = 1 then
        --insert into table1 
        
      elsif :new.status = 9 then
        -- insert into table12 
       
      end if;
    end;
      

  3.   

    create or replace trigger tri_tb before update of status on tb for each row
    begin
    if :new.status=1 then
    insert into table1 select .....;
    elsif :new.status=9 then
    insert into table2 select .....;
    end if;
    end;
      

  4.   

    触发器里面  :new.col 表示名为col的字段的新的值,:old.col 表示名为col的字段修改的旧的值
    :old.col只有在修改或者删除的情况下有 在新增的情况下没有