Solved

execute immediate issue

Posted on 2007-11-21
6
1,299 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
6 Comments
 
LVL 23

Expert Comment

by:Ashish Patel
Comment Utility
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
Comment Utility
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
Comment Utility
Try to give the "CREATE TABLE" privilege explicitly to your user as a DBA.

like

grant CREATE TABLE to VDB_OWNER
/
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 23

Expert Comment

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

Expert Comment

by:Naveen Kumar
Comment Utility
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 31

Expert Comment

by:awking00
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now