创建仅在创建新表时运行的触发器

Creating a trigger to only run when a new table is being created(创建仅在创建新表时运行的触发器)
本文介绍了创建仅在创建新表时运行的触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以用它来创建 DDL 创建触发器;

I know that I can use this to create DDL create trigger;

CREATE OR REPLACE TRIGGER 
  create_table_trigger
  AFTER CREATE ON SCHEMA
DECLARE
BEGIN
END;

问题是这个触发器会在像创建序列"这样的 DDL 上运行;我如何只对创建表"DDL 执行此操作?

Problem is this trigger would run on DDLs like 'Create sequence'; how can I only execute this for 'Create Table' DDLs?

推荐答案

CREATE OR REPLACE TRIGGER 
  create_table_trigger
  AFTER CREATE ON SCHEMA
BEGIN
  IF SYS.DICTIONARY_OBJ_TYPE = 'TABLE' THEN
      ....
END;

有关 EVENT 属性的列表,请参阅此页面
http://ist.marshall.edu/ist480adbp/plsql_triggers.html(链接是下)

For a list of EVENT attributes, refer to this page
http://ist.marshall.edu/ist480adbp/plsql_triggers.html (link is down)

Wayback machine 链接到上面死链接的内容:https://web.archive.org/web/20110809071133/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

据我所知,dictionary_obj_type 是其中之一表|序列|过程|索引|功能|类型|包装

As far as I know, dictionary_obj_type is one of TABLE|SEQUENCE|PROCEDURE|INDEX|FUNCTION|TYPE|PACKAGE

而dictionary_obj_name 只是表/序列/过程/等的名称.

And dictionary_obj_name is just the name of the table/sequence/proc/etc.

  • dictionary_obj_type 返回触发触发器的 DDL 操作发生的字典对象的类型.
  • dictionary_obj_name 返回触发触发器的 DDL 操作发生的字典对象的名称.
  • dictionary_obj_type Returns the type of the dictionary object on which the DDL operation that fired the trigger occurred.
  • dictionary_obj_name Returns the name of the dictionary object on which the DDL operation that fired the trigger occurred.

这篇关于创建仅在创建新表时运行的触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)