Creating a trigger to only run when a new table is being created

爱⌒轻易说出口 提交于 2019-12-18 04:55:08

问题


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;

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


回答1:


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)

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

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

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

  • 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.


来源:https://stackoverflow.com/questions/4812412/creating-a-trigger-to-only-run-when-a-new-table-is-being-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!