Either see
</code>
http://asktom.oracle.com/Misc/RolesAndProcedures.html <code>
(roles are not enabled during the execution of a typical procedure)
or create the procedure with invokers rights....
Here is an example that shows hows this all works:
tkyte@OSI1.WORLD> create or replace procedure create_mytable
2 is
3 begin
4 execute immediate 'create table bonus (name number)';
5 end;
6 /
Procedure created.
That is your procedure as you wrote it basically...tkyte@OSI1.WORLD> create table bonus (name number);
Table created.
tkyte@OSI1.WORLD> drop table bonus;
Table dropped.
So, the above shows I can in fact create a table directly in SQLtkyte@OSI1.WORLD> exec create_myTable
BEGIN create_myTable; END;
*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "TKYTE.CREATE_MYTABLE", line 4
ORA-06512: at line 1
But apparently NOT in plsql. I could get myself granted "CREATE TABLE" (not via a role) to fix that (me, the owner of the procedure)tkyte@OSI1.WORLD> set role none;
Role set.
tkyte@OSI1.WORLD> create table bonus (name number);
create table bonus (name number)
*
ERROR at line 1:
ORA-01031: insufficient privileges
That just proves that this is a role issue -- without roles, I cannot create a tabletkyte@OSI1.WORLD> set role all;
Role set.
tkyte@OSI1.WORLD> create or replace procedure create_mytable
2
AUTHID CURRENT_USER 3 is
4 begin
5 execute immediate 'create table bonus (name number)';
6 end;
7 /
Procedure created.
So, now we use invokers rights, thats the AUTHID CURRENT_USER statment above. Now the procedure will run with the privs of the user executing the query PLUS any and all roles they havetkyte@OSI1.WORLD> exec create_myTable
PL/SQL procedure successfully completed.
and it works...