文章目錄
- 1、禁用,啟用,以及刪除觸發器
- 2、建立禁用的觸發器
- 4、檢查觸發器的有效性
1、禁用,啟用,以及刪除觸發器
alter trigger trigger_name disable;
alter trigger trigger_name enable;
drop trigger trigger_name;
舉例:禁用或者啟用某個表上的全部觸發器
create or replace PROCEDURE settrig(tab IN VARCHAR2,
sch IN VARCHAR DEFAULT NULL,
action IN VARCHAR2) IS
l_action VARCHAR2(10) := UPPER(action);
l_other_action VARCHAR2(10) := 'DISABLED';
BEGIN
IF l_action = 'DISABLE' THEN
l_other_action := 'ENABLED';
END IF;
FOR rec IN (SELECT trigger_name
FROM user_triggers
WHERE table_owner = UPPER(NVL(sch, USER))
AND table_name = tab
AND status = l_other_action) LOOP
EXECUTE IMMEDIATE 'ALTER TRIGGER ' || rec.trigger_name || ' ' ||
l_action;
END LOOP;
END;
2、建立禁用的觸發器
create or replace TRIGGER just_testing
AFTER INSERT ON abc DISABLE
BEGIN
NULL;
END;
--注意,重新編譯已經禁用的觸發器,會啟用觸發器。
3、與觸發器相關的資料字典視圖
DBA_TRIGGERS
ALL_TRIGGERS
USER_TRIGGERS
相關詳細資料請參考oracle reference
4、檢查觸發器的有效性
SQL> SELECT object_name,
object_type,
status
FROM user_objects
WHERE object_name = 'INVALID_TRIGGER';