基础就不说了,放一个用的东西比较多的触发器,以后方便看
create or replace trigger test1_update
after update
on test1
for each row
declare
pragma autonomous_transaction;
field VARCHAR2(2000);
sum1 integer;
begin
select count(1) into sum1 from changelog where id=:new.id and table_name=‘test1‘;
if sum1<>0 then
select update_field into field from changelog where id=:new.id and table_name=‘test1‘;
end if;
if updating (‘clum1‘) then
select field||‘clum1,‘ into field from dual;
end if;
if updating (‘clum2‘) then
select field||‘clum2,‘ into field from dual;
end if;
insert into changelog values(:old.id,‘test1‘,‘0‘,‘update‘,field,sysdate,‘‘,‘‘,‘‘);
end;
输出语句是dbms_output.put_line(
‘name字段被修改‘
);
方便查看变量的值对不对。