This might give you some clue: http://asktom.oracle.com/~
Longer discussion is here:
http://216.239.39.104/sear
Main Topics
Browse All TopicsI'm GETTING ORA-01031 ON EXECUTE IMMEDIATe while executing proc.
I have a privelge to create table, which privileges need to be granted to my account to execute this command successfully?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This might give you some clue: http://asktom.oracle.com/~
Longer discussion is here:
http://216.239.39.104/sear
1)It's a bad habit to create objects within your procedure. You can always create it outside and use it in the procedure .
2)The reason why you are getting this error is because the user who's executing the procedure does not have "Create Table" privileges.You need to grant the privilege to the user.
As sys execute the following command:
grant create table to <user_name>;
Hi Smena,
Riazpk is correct, you cannot do EXECUTE IMMEDIATE ('CREATE TABLE TEST (COL CHAR(5)') within a procedure unless the owner of the procedure has a direct 'GRANT CREATE TABLE'. It does not work if the grant is available through a role like CONNECT etc.
Another comment repeating what Catchmeifuwant said, "It's a bad habit to create objects within your procedure (even temporary tables)". One reason is that you have write code to make sure the procedure cannot be run by two users at the same time otherwise you will get errors due to already existing objects.
Also you have to take care of the cleanup. You need to either drop the object at the beginning of the procedure, or at the end of the procedure otherwise your procedure will not be able to create the object if it already exists from a prior execution.
This is the content in the link ( http://asktom.oracle.com/~
Why do I get a "ORA-01031: insufficient privileges" or "PLS-00201: identifier 'x' must be declared" in my stored procedures?
Roles are never enabled during the execution of a procedure except in the special case of Invokers Rights which is a new feature in Oracle8i, release 8.1.
This fact is documented application developers guide:
Privileges Required to Create Procedures and Functions
To create a stand-alone procedure or function, or package specification or
body, you must meet the following prerequisites:
• You must have the CREATE PROCEDURE system privilege to create a
procedure or package in your schema, or the CREATE ANY
PROCEDURE system privilege to create a procedure or package in
another user’s schema.
Attention: To create without errors, that is, to compile the procedure
or package successfully, requires the following additional privileges:
The owner of the procedure or package must have been explicitly
granted the necessary object privileges for all objects referenced within
the body of the code; the owner cannot have obtained required
privileges through roles.
If the privileges of a procedure’s or package’s owner change, the procedure
must be reauthenticated before it is executed. If a necessary privilege to a
referenced object is revoked from the owner of the procedure (or package), the
procedure cannot be executed.
</quote>
Try this:
SQL> set role none;
SQL> "statement you want to test to see if it'll work in a procedure"
If you can do it in plus with no roles you can do it in a procedure. If you can't, you must have the privelege from a role and hence won't be able to do it in a procedure (unless you are using Invokers rights in Oracle8i. See the PLSQL documentation for more information on this feature and make sure you understand the ramifications). To be able to perform that operation in a typical procedure, you need to have that privelege granted directly to you.
Business Accounts
Answer for Membership
by: SDuttaPosted on 2004-09-27 at 13:04:46ID: 12163838
You have to give us a little more clue than that...
EXECUTE IMMEDIATE (what?)
Can you paste your script please.