问题
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