Oracl create table from inside a proceduree

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
toookiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Was create table granted through a role?

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
toookiAuthor Commented:
Ok, not sure. Will check. Thanks.

Was wondering that the delete statement worked..
Anyway asking DBA..
0
slightwv (䄆 Netminder) Commented:
Are you sure it did?  The error message says it was generated at line 3.  That is the drop table line.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

toookiAuthor Commented:
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
slightwv (䄆 Netminder) Commented:
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
slightwv (䄆 Netminder) Commented:
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
toookiAuthor Commented:
I am creating the table via a script that will let me create a table with variable # of columns..
thanks
0
JacobfwCommented:
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
slightwv (䄆 Netminder) Commented:
>>be given explicitly to the user

I believe I already covered this.
0
toookiAuthor Commented:
Thank you.
It worked in a different environment..where probably I have those direct privileges.
Thanks a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.