?
Solved

Oracl create table from inside a proceduree

Posted on 2011-10-06
10
Medium Priority
?
708 Views
Last Modified: 2012-08-14
In Oracle (11gR2), I have created a procedure:

CREATE OR REPLACE PROCEDURE myproc
BEGIN

  s_sql_delete := 'DROP TABLE mytab1';
  EXECUTE IMMEDIATE s_sql_delete;

  s_sql_insert := 'CREATE TABLE test2 (f1 date)';
  EXECUTE IMMEDIATE s_sql_insert;

The delete table works but the create table does not ..

The user has create table privilege. And it can create table on sql prompt.

I get the error :

ORA-01031: insufficient privileges
ORA-06512: at "myproc", line xx
ORA-06512: at line 3
0
Comment
Question by:toooki
  • 5
  • 4
10 Comments
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 total points
ID: 36926527
Was create table granted through a role?

When doing DML in a procedure you muse explicitly grant the priv to the user.
0
 

Author Comment

by:toooki
ID: 36926541
Ok, not sure. Will check. Thanks.

Was wondering that the delete statement worked..
Anyway asking DBA..
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36926556
Are you sure it did?  The error message says it was generated at line 3.  That is the drop table line.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:toooki
ID: 36926580
I verified many times, yes it did DELETE..

No I modified the content of the procedure before posting, it actually failed at the create table itself..thanks
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36926597
I can only go by what you post.

Off the top of my head I cannot think why you can drop a table and not create one.
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36926606
You also realize it is not the greatest of idea to drop and create tables inside a procedure.

Will a global temporary table not work for what you need?
0
 

Author Comment

by:toooki
ID: 36926675
I am creating the table via a script that will let me create a table with variable # of columns..
thanks
0
 
LVL 7

Expert Comment

by:Jacobfw
ID: 36930284
For a execute immediate, the privledge of "grant create table" must be given explicitly to the user (not through a role).

grant create any table to 'user';

then try your procedure again.
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36930676
>>be given explicitly to the user

I believe I already covered this.
0
 

Author Comment

by:toooki
ID: 36934846
Thank you.
It worked in a different environment..where probably I have those direct privileges.
Thanks a lot.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

862 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