Solved

Let Oracle Trigger do the work

Posted on 2014-10-08
2
401 Views
Last Modified: 2014-10-27
I need to create a trigger to create the synonyms when any new table is created.

Currently; this is a manual task as below:-
Create created (say Test). Create table test a(number);

After that the manual tasks as below:-
create public synonym test for test;
grant select,insert,delete on test to emp_role;

I need help in automate the process using trigger. ( The trigger should create the synonym for the new objects and also grant privileges to roles).
0
Comment
Question by:Oranew
2 Comments
 
LVL 16

Accepted Solution

by:
Wasim Akram Shaik earned 500 total points
ID: 40368173
You directly cannot use grants in triggers, you may have to use Pragma and call it via a procedure..

first create the procedure and afterwards create the trigger

Try something like this, this is an extract from the oracle forums website, https://community.oracle.com/thread/402826

create or replace TRIGGER TRIG_CREATE_TABLE
AFTER CREATE ON SCHEMA
begin
  if ora_dict_obj_type='TABLE' then
    grant_privs (ora_dict_obj_owner, ora_dict_obj_name);
  end if;
end;

create or replace procedure grant_privs (p_owner in varchar2, p_tablename in varchar2) authid current_user
is
   pragma autonomous_transaction;
begin
   execute immediate 'grant select, insert, delete, update on ' || p_owner ||'.'|| p_tablename ||' to role_crud_mtd';
execute immediate 'create public synonym '||p_tablename||' for '||p_table_name;

   commit;
end grant_privs;
0
 

Author Closing Comment

by:Oranew
ID: 40407707
Thank you so much.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now