Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing an Oracle Stored Proc as Another User

I'm mostly an oracle novice, so forgive me if this is a stupid question...

I have a schema called 'CODE' with a stored proc that executes arbitrary SQL (for now, please ignore the potential security issues associated with that). The SQL that is passed in will select data; but all of the data resides in either schema A, B, or C - but the SQL will only ever select from ONE schema at a time.

For example: User of type A creates a string 'SELECT * FROM A.USERTABLE' - while user of type B creates a string 'SELECT * FROM B.USERTABLE'.

What I'm trying to do is allow the user to not explicitly specify their schema. In the front-end .net application; I already know if they are type A, B, or C. I want all three to simply enter 'SELECT * FROM USERTABLE'.

The problem I'm having is that I don't know how to do that. My app can only execute proc in the 'CODE' schema - so I can't just duplicate the code and let user A call 'A.ExecuteSQL'.

I've tried a few things; but nothing has worked thus far. I want the ExecuteSQL proc to stay in the CODE schema; but when 'USERTABLE' gets passed in, I need it to know that sometimes that means A.USERNAME and sometimes B.USERNAME.

Any suggestions?

like image 897
Rob P. Avatar asked Mar 04 '10 03:03

Rob P.


People also ask

How do I give a procedure permission in Oracle?

The syntax for granting EXECUTE privileges on a function/procedure in Oracle is: GRANT EXECUTE ON object TO user; EXECUTE. The ability to compile the function/procedure.

How do I grant a function privilege to user in Oracle?

To create or replace a standalone function in your schema, you must have the CREATE PROCEDURE system privilege. To create or replace a standalone function in another user's schema, you must have the CREATE ANY PROCEDURE system privilege.

How do I switch users in Oracle SQL Developer?

In the SQL Developer Connections navigator, expand the SYSTEM connection and right-click the Other Users node. Right-click NICK and select Edit User. In the Create/Edit User dialog box, in the User tab, select (check) Password expired (user must change next login).


1 Answers

Use:

ALTER SESSION SET CURRENT_SCHEMA = schema

That is the equivalent to SQL Server's EXECUTE AS syntax.

like image 183
OMG Ponies Avatar answered Oct 20 '22 22:10

OMG Ponies