Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invoke GRANT in Trigger?

Status
Not open for further replies.

stoggers

Vendor
May 30, 2001
93
US
Hi,

Is it possible to invoke the GRANT statement in a trigger?

I have a packaged application that inserts rows in a 'user' table - thereby creating application users.

What I would also like this to do is create Oracle users & grant appropriate permissions.

Not being able to alter the application directly means that the use of a trigger is the only way that I can execute the statements.
 
I haven't tried it, but if you're using 8i you should be able to build the command within the trigger and then do an "Execute Immediate" call, passing in the command.
Something like:
.
.
.
v_command := 'GRANT EXECUTE ON my_procedure TO '||:new.user;
EXECUTE IMMEDIATE v_command;
.
.
.
 
You can also use the package DBMS_SESSION for running these statements from within PL/SQL:

-- This package provides access to SQL "alter session" statements, and
-- other session information from, stored procedures.
 
Execute immediate will not work due to explicit commit issued by DDL statement.

You have to create some stored procedure with PRAGMA AUTONOMOUS_TRANSACTION and place your DDL code called via execute immediate or dbms_sql to it and then call it from trigger.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top