我正在尝试创建一个DDL触发器AFTER CREATE
,该DDL触发器在被调用时会产生另一个触发器。
所以我写了一些测试代码,这里是:
CREATE OR REPLACE TRIGGER Test_Trigger
AFTER CREATE ON SCHEMA
WHEN (ORA_DICT_OBJ_TYPE = 'TABLE')
BEGIN
EXECUTE IMMEDIATE q'[
CREATE OR REPLACE TRIGGER People_Trigger
BEFORE UPDATE OF ID ON People
BEGIN
DBMS_OUTPUT.PUT_LINE('This code here doesn''t really matter.');
END;
]';
END;
/
CREATE TABLE People (
ID NUMBER(6) PRIMARY KEY
, Name VARCHAR2(31)
, Parent_ID NUMBER(6) REFERENCES People (ID)
);
但是尝试创建表People
时出现以下错误:
Error report -
ORA-00604: error occurred at recursive SQL level 1
ORA-01031: insufficient privileges
ORA-06512: on line 2
00604. 00000 - "error occurred at recursive SQL level %s"
*Cause: An error occurred while processing a recursive SQL statement
(a statement applying to internal dictionary tables).
*Action: If the situation described in the next error on the stack
can be corrected, do so; otherwise contact Oracle Support.
尽管如果我在People_Trigger
之外创建该触发器(Test_Trigger
),它也可以正常工作。
答案 0 :(得分:0)
我完成了以下练习,发现权限不足(创建触发器)时会引发错误。
-- execute from sys user
--
revoke create trigger from <your_user>;
-- execute from your user
--
CREATE OR REPLACE TRIGGER Test_Trigger
AFTER CREATE ON SCHEMA WHEN (ORA_DICT_OBJ_TYPE = 'TABLE')
BEGIN
EXECUTE IMMEDIATE q'[
CREATE OR REPLACE TRIGGER People_Trigger
BEFORE UPDATE OF ID ON People
BEGIN
DBMS_OUTPUT.PUT_LINE('This code here doesn''t really matter.');
END;
]';
END;
/
-- execute from your user
--
CREATE TABLE People (
ID NUMBER(6) PRIMARY KEY
, Name VARCHAR2(31)
, Parent_ID NUMBER(6) REFERENCES People (ID)
);
On execution, You will find following error:
Error report -
ORA-04088: error during execution of trigger 'TEJASH.TEST_TRIGGER'
ORA-00604: error occurred at recursive SQL level 1
ORA-01031: insufficient privileges
ORA-06512: at line 2
04088. 00000 - "error during execution of trigger '%s.%s'"
*Cause: A runtime error occurred during execution of a trigger.
*Action: Check the triggers which were involved in the operation.
Now,
-- execute from sys user
--
grant create trigger to <your_user>;
-- execute from your user
--
CREATE TABLE People (
ID NUMBER(6) PRIMARY KEY
, Name VARCHAR2(31)
, Parent_ID NUMBER(6) REFERENCES People (ID)
); -- successful
SELECT
TRIGGER_NAME,
TRIGGER_TYPE,
TRIGGERING_EVENT,
TABLE_OWNER
FROM
USER_TRIGGERS
WHERE
TRIGGER_NAME = 'PEOPLE_TRIGGER';