Insufficient privs when trying to execute an Oracle stored proc

I have created the stored procedure below. If I try to execute it, I am getting an insufficient priviledges error message.
Does anyone have any idea why?


CREATE OR REPLACE PROCEDURE SIMPLE
IS
 BEGIN
  EXECUTE IMMEDIATE 'CREATE TABLE ELIX (ID INT NULL);
  EXECUTE IMMEDIATE 'GRANT INSERT ON B1';
  EXECUTE IMMEDIATE 'INSERT INTO ELIX (ID) VALUES (1)';
END;

EXECUTE SIMPLE

Error starting at line : 3 in command -
EXECUTE SIMPLE
Error report -
ORA-01031: "insufficen
*Cause: An attempt was made to perform a database operation without the necessary privileges
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
 
Geert GConnect With a Mentor Oracle dbaCommented:
it's not that "simple"

yer grant is wrong
grant insert on elix to B1

Open in new window


which user is executing what ?
0
 
slightwv (䄆 Netminder) Commented:
You either don't have create table privileges or grant insert privileges.

For stored procedures the permissions need to be granted to the user that owns the procedure directly and not through a role.

Also:  You really shouldn't be creating tables and performing grants inside a stored procedure like that.  Oracle normally doesn't need to do that.
0
 
Mark GeerlingsConnect With a Mentor Database AdministratorCommented:
Yes, Geert is correct.  Your syntax was wrong for the grant command.  But, the bigger problem here is what slightwv suggested: "You really shouldn't be creating tables and performing grants inside a[n Oracle] stored procedure."

Those actions may be common in SQL Server stored procedures, but that doesn't mean you should try to do things that way in Oracle.  Oracle and SQL Server are very different databases!
0
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.

All Courses

From novice to tech pro — start learning today.