Solved

execute immediate issue

Posted on 2007-11-21
6
1,301 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
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
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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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.  …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to take different types of Oracle backups using RMAN.

948 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

23 Experts available now in Live!

Get 1:1 Help Now