Dynamic SQL - Insufficient privileges [message #559966] |
Sun, 08 July 2012 06:57  |
 |
nb.mopidevi@gmail.com
Messages: 4 Registered: January 2012
|
Junior Member |
|
|
Hello Guys,
I am new to Dynamic SQL..
I create a procedure to get any DDL done against sample HR schema as follows.
it goes well!
Now when i try to test my procedure with some DDL command passing to the procedure i've created..
strange! oracle throws an error as in the /*ERROR!!!!*/ block..
I don't understand why i am facing such an error..
Any idea what goes wrong??
Thanks in advance 
/* Product an Version on my machine */
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
/* Get DDL done ! */
CREATE OR REPLACE PROCEDURE exec_ddl(ddl_string IN VARCHAR2)
IS
BEGIN
EXECUTE IMMEDIATE ddl_string;
END;
/
/* anonymous to test */
BEGIN
exec_ddl('CREATE TABLE sam_tab (sam_num NUMBER(4))');
END;
/
/* ERROR !!!! */
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "HR.EXEC_DDL", line 4
ORA-06512: at line 2
[EDITED by LF: fixed topic title typos]
[Updated on: Sun, 08 July 2012 09:16] by Moderator Report message to a moderator
|
|
|
|
Re: Dyanamic SQL - Insufficient priviliges [message #559970 is a reply to message #559967] |
Sun, 08 July 2012 07:09   |
John Watson
Messages: 8981 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Welcome to the forum. Please read our OraFAQ Forum Guide and How to use [code] tags and make your code easier to read
Your problem will be that you have not been granted the CREATE TABLE privilege directly. You may have it through a role, but roles cannot be used in pl/sql. Like this:orcl>
orcl> CREATE OR REPLACE PROCEDURE exec_ddl(ddl_string IN VARCHAR2)
2 IS
3 BEGIN
4 EXECUTE IMMEDIATE ddl_string;
5 END;
6 /
Procedure created.
orcl> BEGIN
2 exec_ddl('CREATE TABLE sam_tab (sam_num NUMBER(4))');
3 END;
4 /
BEGIN
*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "JON.EXEC_DDL", line 4
ORA-06512: at line 2
orcl> grant create table to jon;
Grant succeeded.
orcl> BEGIN
2 exec_ddl('CREATE TABLE sam_tab (sam_num NUMBER(4))');
3 END;
4 /
PL/SQL procedure successfully completed.
orcl>
|
|
|
|
|
|
|
|