oracle 用觸發器記錄操作
阿新 • • 發佈:2019-01-04
create or replace trigger tri_dbset AFTER INSERT OR UPDATE OR DELETE
on t_sjzx_dbset for each row
begin
IF INSERTING THEN
insert into t_tri_dbset(id,name,remark,tablename,classid,actfield) values(:new.id,:new.name,:new.remark,:new.tablename,:new.classid,1);
ELSIF UPDATING THEN
insert into t_tri_dbset(id,name,remark,tablename,classid,actfield) values(:new.id,:new.name,:new.remark,:new.tablename,:new.classid,2);
ELSIF DELETING THEN
insert into t_tri_dbset(id,name,remark,tablename,classid,actfield) values(:old.id,:old.name,:old.remark,:old.tablename,:old.classid,3);
END IF;
END;
幾個關鍵:
1、AFTER INSERT OR UPDATE OR DELETE
2、for each row 行級,不加就是表級
3、:new 新記錄
4、:old 舊記錄