oracle触发器(当插入或删除或修改一张表时,能把新数据同步到另一张 ...

create or replace trigger testT
AFTER INSERT OR UPDATE OR DELETE ON A
for each row
declare
-- local variables here
begin
IF INSERTING THEN
     INSERT INTO b(a,b) VALUES(:NEW.a,:NEW.b);
ELSIF DELETING THEN
    DELETE FROM b WHERE a=:OLD.a;
ELSE
     UPDATE b SET b=:NEW.b WHERE a=:OLD.a;
END IF;
end testT;

SQL> desc a
Name Type         Nullable Default Comments
---- ------------ -------- ------- --------
A    VARCHAR2(20) Y                        
B    VARCHAR2(20) Y                        

SQL> desc b;
Name Type         Nullable Default Comments
---- ------------ -------- ------- --------
A    VARCHAR2(20) Y                        
B    VARCHAR2(20) Y                        


SQL> insert into a values('a','b');

1 row inserted

SQL> commit;

Commit complete

SQL> select * from b;

A                    B
-------------------- --------------------
a                    b

SQL> update a set b='c' where a='a';

1 row updated

SQL> commit;

Commit complete

SQL> select * from b;

A                    B
-------------------- --------------------
a                    c

SQL> delete from a where a='a';

1 row deleted

SQL> commit;

Commit complete

SQL> select * from b;

A                    B
-------------------- --------------------

SQL>



郑重声明:资讯 【oracle触发器(当插入或删除或修改一张表时,能把新数据同步到另一张 ...】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——