Solved

execute immediate issue

Posted on 2007-11-21
6
1,312 Views
Last Modified: 2013-12-07
1  CREATE OR REPLACE PROCEDURE X AS
 2  BEGIN
 3   begin
 4  execute immediate 'CREATE TABLE XYZ NOLOGGING AS SELECT * FROM COMMITMENTS_EXTRACT_BYUSER ';
 5  end;
 6  EXECUTE IMMEDIATE 'DROP TABLE COMMITMENTS_EXTRACT_BYUSER';
 7  EXECUTE IMMEDIATE 'RENAME XYZ TO COMMITMENTS_EXTRACT_BYUSER';
 8* END X;
 9  /

rocedure created.

QL> EXECUTE X;
EGIN X; END;


RROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "VDB_OWNER.X", line 4
ORA-06512: at line 1


But the below code is working

 1  DECLARE
 2  BEGIN
 3   execute immediate 'CREATE TABLE XYZ NOLOGGING AS SELECT * FROM COMMITMENTS_EXTRACT_BYUSER WHER
 4  EXECUTE IMMEDIATE 'DROP TABLE COMMITMENTS_EXTRACT_BYUSER';
 5  EXECUTE IMMEDIATE 'RENAME XYZ TO COMMITMENTS_EXTRACT_BYUSER';
 6* END;
 7  /

PL/SQL procedure successfully completed.

Why is my initial code not working,how can i achieve the results using my initial code.
Rgds,
Suhin
0
Comment
Question by:suhinrasheed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20326632
Your user is not having permissions to execute procedure i guess. Please gran all previlages to user VDB_OWNER.X
0
 

Author Comment

by:suhinrasheed
ID: 20326671
i have created the procedure in VDB_OWNER and the schema has privileges to execute procedures,but the issue is there
0
 
LVL 27

Accepted Solution

by:
sujith80 earned 500 total points
ID: 20326672
Try to give the "CREATE TABLE" privilege explicitly to your user as a DBA.

like

grant CREATE TABLE to VDB_OWNER
/
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20326674
check for permission for creating table too which is at line 4
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 20326802
when running something from sql prompt, use set serveroutput on
and also dbms_output.put_line(..) to see where the error is coming.

Also have an exception handling section whether it is a procedure or anonymous block, and write some text to the screen or debug table in the exception handler which can print/insert the SQLCODE and SQLERRM.

Thanks
0
 
LVL 32

Expert Comment

by:awking00
ID: 20327975
Try adding the following to your procedure and see what happens
CREATE OR REPLACE PROCEDURE X
AUTHID CURRENT_USER  ==>This syntax
AS
BEGIN
...
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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

724 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