`
sgl124764903
  • 浏览: 170254 次
  • 性别: Icon_minigender_1
  • 来自: 邯郸
社区版块
存档分类
最新评论

触发器 当表中一个字段的值改变时,另一个字段也发生改变

阅读更多

表table1 字段a,b  a,b 一一对应

表table2 字段a,c   a,c 一一对应

要求,在表table1中字段a发生改变时,触动字段b发生改变,字段b的值为表table2中字段a对应的字段c的值。

create or replace trigger tr_table1
 before update
  of a
  on table1
 referencing old as old_value
     new as new_value
 for each row
DECLARE
  XX VARCHAR2(7);
begin
  select c
    into XX
    FROM table2 t
   WHERE t.a = :new_value.a;
  :new_value.b := XX;
end;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics