觸發器寫法:
create or replace trigger testTrigger
before insert or update or delete
on t_yunwei_group
for each row
declare
-- local variables here
begin
if inserting then
insert into t_yunwei_stalocation t1 (t1.c_groupid,t1.c_groupName,t1.c_filecontent) values (:NEW.c_Groupid,:NEW.c_groupname,' ');
end if;
if updating then
update t_yunwei_stalocation t1 set t1.c_groupname=:NEW.c_groupname where t1.c_groupid=:NEW.c_Groupid;
end if;
if deleting then
delete from t_yunwei_stalocation t1 where t1.c_groupid=:OLD.c_Groupid;
end if;
end testTrigger;
注: :old 與:new 的區別:
顧名思義,new是新插入的數據,old是原來的數據
insert只會有new,代表着要插入的新記錄
delete只會有old,代表着要刪除的記錄
update由於執行的是先刪除舊的記錄,再插入新的記錄,因此new和old都會有,且含義與上面的相同
注:update觸發器,可根據具體需求選擇記錄舊記錄還是新記錄。
oracle簡單觸發器
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.