Create trigger on Oracle from a user that listens to events for another user

做~自己de王妃 提交于 2020-01-16 00:43:10

问题


I have two Oracle schemas A & B.

Can I create a trigger in schema A that will listen to Create Tables on Schema B? If yes, which grants do I need to do?


回答1:


Yes, you can. The user a needs to have CREATE ANY TRIGGER:

As DBA:

CREATE USER a IDENTIFIED BY a;
GRANT CREATE SESSION, CREATE ANY TRIGGER TO a;

CREATE USER b IDENTIFIED BY b;
GRANT CREATE SESSION TO b;

As a:

CREATE OR REPLACE TRIGGER a.create_trigger
  BEFORE CREATE ON b.SCHEMA
BEGIN
  raise_application_error(num => -20000,  msg=> 'create_trigger vetoes');
END;
/

As b:

CREATE TABLE t(i INT);
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-20000: create_trigger vetoes
ORA-06512: at line 2

You'll have to fine-tune this trigger, it will fire not only for CREATE TABLE but for all CREATE statements...



来源:https://stackoverflow.com/questions/24960225/create-trigger-on-oracle-from-a-user-that-listens-to-events-for-another-user

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