Home » SQL & PL/SQL » SQL & PL/SQL » Insufficient privileges when creating Tables using Execute Immediate (Oracle 10g)
Insufficient privileges when creating Tables using Execute Immediate [message #453720] Fri, 30 April 2010 07:00 Go to next message
srivaths
Messages: 60
Registered: June 2005
Location: France
Member

Hi,

SQL> connect sys as sysdba
Enter password:
Connected.
SQL> grant dba to temp;

Grant succeeded.

SQL> connect temp
Enter password:
Connected.
SQL>
SQL> create or replace procedure tempproc
  2  is
  3  begin
  4  execute immediate 'create table temp_table(a varchar2(10))';
  5  end;
  6  /

Procedure created.

SQL> exec tempproc;
BEGIN tempproc; END;

*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "TEMP.TEMPPROC", line 4
ORA-06512: at line 1


SQL>
SQL> declare
  2  begin
  3  execute immediate 'create table temp_table(a varchar2(10))';
  4  end;
  5  /

PL/SQL procedure successfully completed.

SQL> desc temp_table;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 A                                                  VARCHAR2(10)



Why am I not able to create a table from procedure using execute immediate?
Re: Insufficient privileges when creating Tables using Execute Immediate [message #453722 is a reply to message #453720] Fri, 30 April 2010 07:07 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
Because privs granted through roles are ignored in stored procedures. You need to grant create table directly to the user.
Re: Insufficient privileges when creating Tables using Execute Immediate [message #453726 is a reply to message #453722] Fri, 30 April 2010 07:15 Go to previous messageGo to next message
srivaths
Messages: 60
Registered: June 2005
Location: France
Member

Thanks for sharing cookiemonster.
Re: Insufficient privileges when creating Tables using Execute Immediate [message #453736 is a reply to message #453722] Fri, 30 April 2010 07:58 Go to previous message
Michel Cadot
Messages: 68774
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
cookiemonster wrote on Fri, 30 April 2010 14:07
Because privs granted through roles are ignored in stored procedures. You need to grant create table directly to the user.

...or create the procedure with the option "AUTHID CURRENT_USER".

Regards
Michel

Previous Topic: ORA-00997: illegal use of LONG datatype (merged)
Next Topic: ORA-01555 Snapshot Too Old
Goto Forum:
  


Current Time: Tue Jan 20 11:51:21 CST 2026