日期:2014-05-17  浏览次数:21070 次

求一个ORACLE触发器的写法,内详.
其实流程并不麻烦,我写得比较详细,希望大家帮帮忙。

    假设系统有2张表,mainTable(主表)和tempTable(中转表)
当表,mainTable(主表)发生insert,update事件时(假设不考虑并发访问该表),利用触发器把   mainTable中被insert,update更新之后的数据,和更新的操作(以字符串的形式,如’Update’或‘Insert’)插入一张临时表(tempTable)中,       因此最后tempTable中就包括mainTable更新之后的更条数据   和所对应的操作即insert或update

对应的触发器如何写?谢谢。


------解决方案--------------------
create or replace trigger test_tr
after insert or update on mainTable
for each row
begin
if inserting then
insert into tempTable values(:new.字段, 'insert ');
elsif updating then
insert into tempTable values(:new.字段, 'update ');
end if;
end;
/