oracle 创建仅在创建新表时运行的触发器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4812412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a trigger to only run when a new table is being created
提问by Tolga E
I know that I can use this to create DDL create trigger;
我知道我可以用它来创建 DDL 创建触发器;
CREATE OR REPLACE TRIGGER
create_table_trigger
AFTER CREATE ON SCHEMA
DECLARE
BEGIN
END;
Problem is this trigger would run on DDLs like 'Create sequence'; how can I only execute this for 'Create Table' DDLs?
问题是这个触发器会在像“创建序列”这样的 DDL 上运行;我怎样才能只对“创建表”DDL 执行此操作?
回答by RichardTheKiwi
CREATE OR REPLACE TRIGGER
create_table_trigger
AFTER CREATE ON SCHEMA
BEGIN
IF SYS.DICTIONARY_OBJ_TYPE = 'TABLE' THEN
....
END;
For a list of EVENT attributes, refer to this page
http://ist.marshall.edu/ist480adbp/plsql_triggers.html(link is down)
有关 EVENT 属性列表,请参阅此页面
http://ist.marshall.edu/ist480adbp/plsql_triggers.html(链接已关闭)
Wayback machine link to the contents of the dead link above: https://web.archive.org/web/20110809071133/http://ist.marshall.edu/ist480adbp/plsql_triggers.html
回车机链接到上面死链接的内容:https: //web.archive.org/web/20110809071133/http: //ist.marshall.edu/ist480adbp/plsql_triggers.html
As far as I know, dictionary_obj_type is one of TABLE|SEQUENCE|PROCEDURE|INDEX|FUNCTION|TYPE|PACKAGE
据我所知,dictionary_obj_type 是 TABLE|SEQUENCE|PROCEDURE|INDEX|FUNCTION|TYPE|PACKAGE 之一
And dictionary_obj_name is just the name of the table/sequence/proc/etc.
而dictionary_obj_name 只是表/序列/过程/等的名称。
- dictionary_obj_typeReturns the type of the dictionary object on which the DDL operation that fired the trigger occurred.
- dictionary_obj_nameReturns the name of the dictionary object on which the DDL operation that fired the trigger occurred.
- dictionary_obj_type返回发生触发触发器的 DDL 操作的字典对象的类型。
- dictionary_obj_name返回发生触发触发器的 DDL 操作的字典对象的名称。