Unable to execute EXECUTE IMMEDIATE statement in a stored procedure...

Hi People,
I use oracle 10g.In which i tried a procedure with follwing code and am thrown with the error that says,
SQL>   create or replace procedure ptable(ptab varchar2) is
  2  lstmt varchar(200);
  3  begin
  4  lstmt:='CREATE TABLE '||ptab||'(a int,b varchar2(30)) ';
  5  execute immediate lstmt;
  6  end;
  7  /
Procedure created.
SQL>  exec ptable('hos');
BEGIN ptable('hos'); END;
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "VIDYA.PTABLE", line 5
ORA-06512: at line 1Procedure has been created but error occurs while executing it.why do i get this error even though i possess DBA privilege?.which permission is lagging for me?.help me with ur suggestions.thanks in advance.
With Regards
VIDS

Yep Yep.Perfect.It was the CREATE ANY TABLE privilege which i was lagging.I granted it to my schema and now got created with the table.Thanku so much for such a quick reply :).
With Regards
VIDS

Similar Messages

  • Can we execute more than one SQL in Stored Procedure?

    Please help me with this.
    I am connecting to SQL SERVER
    Thanks
    Venu

    Hi Venu,
    >>1) Get the input parametrs for SP in from file
    You can pass parameters to the SP from the payload of the message. I am not sure what do you mean by "Getting the parameters for SP in form file"..
    >>2 Configure Receiver JDBC adapter(Synchronous)which executes a STORED PROCEDURE that has some processing logic containing more than one sql statment
    This is no problem. You can have any number of select /update statements inside the stored procedure. But your stored procedure will not return data to XI and that will not be sent as a response to your BPM
    3) Send the response from SP to a BPM
    yes.You can have another Stored procedure that have only one select statement to send response to BPM. You may have to define abstract interfaces .
    hence for 2) and 3) the message payload would be something like this
    <StatementName1>
    <storedProcedureName action=” EXECUTE”>
        <table>realStoredProcedureeName</table>
    <param1 [isInput=”true”] [isOutput=true] type=SQLDatatype>val1</param1>
    </storedProcedureName > 
      </StatementName1>
      <StatementName2>
    <anyName action=” SQL_QUERY”>
    <access>SQL-String with optional placeholder(s)</access>
    <key>
      <placeholder1>value1</placeholder1>
      <placeholder2>value2<placeholder2>    
    </key>
    </anyName > 
      </StatementName2>
    Regards
    Arul
    PS: Mark usefull answers and for more info about points - read the post "Rules of engagement" at the top of the XI forum

  • DDL Statements in a Stored Procedure

    Is there some technique which can be used to execute DDL statements in a stored procedure? I want to drop and recreate a table and a number of indexes. Is there a way for me to do this within a stored procedure?
    Thanks in advance for your assistance!!!

    BEGIN
       EXECUTE IMMEDIATE 'CREATE TABLE bonus (id NUMBER, amt NUMBER)';
    END;http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/13_elems18.htm#33889

  • JDBC/select/async statement to JDBC/stored procedure/sync call

    Hi
    We have JDBC/select/async statement to JDBC/stored procedure/sync call i.e sender and receiver are JDBC.
    PI has to pick all the the records of single internal order number at a time from sender system and upload to receiver JDBc,
    gets the response and routes to sender/insert statement.
    This should run only once per day.
    We will have multiple Internal orders daily, each order consisting of 10 to 20 records but only one IO related records has
    to upload to Receiver/JDBC
    What are the options available ?
    We have thought of following options
    1. SQL query is already to pick, but we have to pick records at one time daily. example: morning,evening or midnight.
       At that time it can pick multiple times but it should not pick through out day
    2. Is there any option in BPM so that we can group IO's at a time and upload ? If so what are the steps need to use
       Any additonal receive step need to be used to pick the records from the table.
    Thanks

    hi
    as i can understando you, you will receive mani IO and you must execute one IO in the receiver SP? if so, you can solve this usssing a ccBPM where you will have to create a mapping(0.N) where the source and the target structure will be the same, the diferrence will be in the occurrance of the target structure which will have to be 0.N (Tab signature in Message Mapping). then back to the ccBPM define a block with the property ForEach. this will  loop any times accord with the number of IO that you receive from the sender. as a result you will execute one SP for each IO.
    so, you ccBPM will be
    RS>TS>BLOCK(Multiline container and single container of source structure)>TS->SS
    RS:Receive Step
    TS:Trans. Step
    SS:Send Step
    Also the container will be:
    source--> type Abs
    source_multiline --> type Abs
    target -->type Abs
    Thanks
    Rodrigo P.
    Edited by: Rodrigo Alejandro Pertierra on Jun 24, 2010 4:54 PM

  • Writing mulitple sql statements in 1 stored procedure

    Hi all, can i know how to create mulitple sql statements in 1 stored procedure??
    Eg the first sql statement will generate few results and my second sql statement will based on the first statement result to execute its second results and my third sql statements will on the second results to generate the final results which will be passed back to jsp pages as a resultset??
    For the time being, i only know how to create a single sql statement in one stored procedure..i had surf through the oracle website but cant find any solution. Can anyone help me?? Samples or links to any website will do.. Thanks alot...

    Hi Irene,
    If I understand your question correctly, then I have already written
    a similar (PL/SQL) stored procedure without any problems.
    However, I do think your question is more suited to the following
    forum:
    http://forums.oracle.com/forums/forum.jsp?id=478021
    I also think it will help others to answer your question if you
    include the following information:
    1. Version of Oracle you are using.
    2. The error message you are getting.
    3. The part of your code that is causing the problem.
    Also, have you looked at the following web sites?
    http://asktom.oracle.com
    http://metalink.oracle.com
    Good Luck,
    Avi.

  • Execute Immediate with SQL in Stored Procedure

    Dear Experts, Please help / guide on below statement which i want to execute in stored procedure,
    EXECUTE IMMEDIATE 'INSERT INTO TABLE
    SELECT COUNT(AGENTID) FROM TABLE_1 A,
    TABLE_2 B, TABLE_3 C
    WHERE A.COL = B.COL AND B.COL = C.COL AND
    DT BETWEEN TRUNC(SYSDATE-1) + 1/24 + 0/12/60/60 AND TRUNC(SYSDATE-1) + 25/24 - 0/12/60/60';
    Edited by: DBA on Dec 3, 2011 3:57 PM

    So what's the problem? The only thing I can see is:
    INSERT INTO TABLETABLE is reserved word, so name your table differently.
    Also, I am assuming the above statement is actually generated from some variables based on some conditions, otherwise why would you need dynamic SQL, just issue:
    INSERT INTO TABLE
    SELECT COUNT(AGENTID) FROM TABLE_1 A,
    TABLE_2 B, TABLE_3 C
    WHERE A.COL = B.COL AND B.COL = C.COL AND
    DT BETWEEN TRUNC(SYSDATE-1) + 1/24 + 0/12/60/60 AND TRUNC(SYSDATE-1) + 25/24 - 0/12/60/60;

  • Failure of EXECUTE IMMEDIATE when in a stored procedure

    Hello,
    this concerns behaviour observed in Oracle 10g on Windows.
    As user "system", I execute from the command line the following:
    SQL> select COUNT(1) from sys.dba_sequences;
    COUNT(1)
    645
    Again I try the same thing from the command line:
    SQL> declare
    2 CNT INTEGER:=0;
    3 STMT VARCHAR2(300);
    4 BEGIN
    5 STMT:='select COUNT(1) from SYS.DBA_SEQUENCES';
    6 EXECUTE IMMEDIATE STMT INTO CNT;
    7 dbms_output.put_line('CNT='||CNT);
    8 end;
    9 /
    CNT=645
    So far so good, clearly this table exists and I have sufficient privileges to access SYS.DBA_SEQUENCES as user system.
    However, if I put this in a stored procedure in a script TEST_SEQ.sql and then execute, I get ORA-00942:
    1. Create or replace Procedure TEST_A1
    2. IS
    3. CNT INTEGER:=0;
    4. STMT VARCHAR2(300);
    5.
    6. BEGIN
    7. STMT:='select COUNT(1) from SYS.DBA_SEQUENCES';
    8.     EXECUTE IMMEDIATE STMT INTO CNT;
    9.     dbms_output.put_line('CNT='||CNT);
    10. END;
    SQL> @ TEST_SEQ.sql
    SQL> exec TEST_A1;
    ORA-00942: Table or view does not exist
    ORA-06512: At "SYSTEM.TEST_A1", line 8
    ORA-06512: At line 1
    Why now does this table not seem to exist when accessed from a stored procedure?

    http://www.google.com/search?btnG=1&q=ora-0942+procedure
    Sybrand Bakker
    Senior Oracle DBA
    Experts: those who do read documentation.

  • User can Execute SQL Statement but not Stored Procedure

    I have a function in Access that calls a stored procedure to update a table. When I run it, it works fine but when the users try to run it, they get an error.
    If I change it run the actual SQL syntax that is in the stored procedure then the users can run it and update the table without any problems, which makes no sense to me. It's doing the same exact thing as the stored procedure. I'd much rather have them be
    able to run the procedures then writing the SQL in VBA modules because that's going to end up being a lot of code.
    Any idea on why it's like this and how to correct it? Any assistance would be appreciated.

    Hello,
    When you give a user permission to run a stored procedure, everything on that procedure but Dynamic SQL will be executed
    without evaluating user permissions on the objects the stored procedure deals with.
    On the link I provided above, you will see how to provide permissions to stored procedures. Try creating database roles, add user to database roles, then assign permissions to database roles.
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Cannot execute a MS SQL Server 2005 Stored procedure via OSB BS

    I created the jca from Jdeveloper using DBAdapter. Then from eclipse I created the wsdl by generating the service. Then I imported all the relevant files in OSB console and created the business service. After executing the business service I get the below error (Pls scroll down).
    I tried many combination s. I tested with a stored procedure which returns only 1 row and 1 column and I hardcoded the column value. I also tried a stored procedure without any input parameters.
    I am sure there is no problem with the deployment of the datasource because I can execute operations to a table for select, update, delete using a business service following the above procedures.
    I created the stored proc following the same steps for select, update, delete. Also one more info is that when I call a stored proc from Oracle XE database it is working fine.
    My JDBC version is 4 . I am using the jar file provided by Microsoft that is sqljdbc4.
    Web Logic Server - 11gR1
    OSB - 11g + coherence + OEPE
    JDeveloper - 11.1.1.3.0
    can someone please help. This is very urgent. I have tried many combination's to get this to work from last 3 days without any luck.
    Help appreciated.
    Regards
    this happens only while executing the stored procedure.
    The invocation resulted in an error: Invoke JCA outbound service failed with application error, exception: com.bea.wli.sb.transports.jca.JCATransportException: oracle.tip.adapter.sa.api.JCABindingException: oracle.tip.adapter.sa.impl.fw.ext.org.collaxa.thirdparty.apache.wsif.WSIFException: servicebus:/WSDL/NEHR_OSB/Lab/SvcNumb [ SvcNumb_ptt::SvcNumb(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'SvcNumb' failed due to: Stored procedure invocation error.
    Error while trying to prepare and execute the OSBLogs.dbo.sp_Numb API.
    An error occurred while preparing and executing the OSBLogs.dbo.sp_Numb API. Cause: java.lang.NullPointerException
    ; nested exception is:
    BINDING.JCA-11811
    Stored procedure invocation error.
    Error while trying to prepare and execute the OSBLogs.dbo.sp_Numb API.
    An error occurred while preparing and executing the OSBLogs.dbo.sp_Numb API. Cause: java.lang.NullPointerException
    Check to ensure that the API is defined in the database and that the parameters match the signature of the API.
    com.bea.wli.sb.transports.jca.JCATransportException: oracle.tip.adapter.sa.api.JCABindingException: oracle.tip.adapter.sa.impl.fw.ext.org.collaxa.thirdparty.apache.wsif.WSIFException: servicebus:/WSDL/NEHR_OSB/Lab/SvcNumb [ SvcNumb_ptt::SvcNumb(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'SvcNumb' failed due to: Stored procedure invocation error.
    Error while trying to prepare and execute the OSBLogs.dbo.sp_Numb API.
    An error occurred while preparing and executing the OSBLogs.dbo.sp_Numb API. Cause: java.lang.NullPointerException
    ; nested exception is:
    BINDING.JCA-11811
    Stored procedure invocation error.
    Error while trying to prepare and execute the OSBLogs.dbo.sp_Numb API.
    An error occurred while preparing and executing the OSBLogs.dbo.sp_Numb API. Cause: java.lang.NullPointerException
    Check to ensure that the API is defined in the database and that the parameters match the signature of the API.

    Hi,
    Even I am getting this kind of problem while executing a stored procedure from OSB.
    I have a stored procedure and i have created wsdl and xsd using JDEV. Now when i am creating a .biz with this wsdl and executing it , this is giving following error:
    <JCA_TRANSPORT_RUNTIME_APPLICATION_FAULT xmlns="http://www.bea.com/transport/2007/05/jca">
    oracle.tip.adapter.sa.api.JCABindingException: oracle.tip.adapter.sa.impl.fw.ext.org.collaxa.thirdparty.apache.wsif.WSIFException: servicebus:/WSDL/DBTest/TryDB [ TryDB_ptt::TryDB(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'TryDB' failed due to: Error while trying to prepare and execute an API.
    An error occurred while preparing and executing the EAIUSER.DIM_Procedure API. Cause: java.sql.SQLException: ORA-06550: line 1, column 7:
    PLS-00201: identifier 'EAIUSER.DIM_PROCEDURE' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    [Caused by: ORA-06550: line 1, column 7:
    PLS-00201: identifier 'EAIUSER.DIM_PROCEDURE' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    ; nested exception is:
    JCA-11811
    Error while trying to prepare and execute an API.
    An error occurred while preparing and executing the EAIUSER.DIM_Procedure API. Cause: java.sql.SQLException: ORA-06550: line 1, column 7:
    PLS-00201: identifier 'EAIUSER.DIM_PROCEDURE' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    [Caused by: ORA-06550: line 1, column 7:
    PLS-00201: identifier 'EAIUSER.DIM_PROCEDURE' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Check to ensure that the API is defined in the database and that the parameters match the signature of the API. Contact oracle support if error is not fixable.
    Please help me in solving this..

  • Executing a Operating System command from Stored Procedure ??

    I want to execute a Operating System command from a PL/SQL Stored Procedure, can anyone suggest me how can I do this ??
    I am on Sun-Solaris with Oracle 8.1.7 database.
    Please do email me at [email protected]
    Thanks in Advance,
    Ramesh L.

    Are you using a webserver? If so, you could make your operating system script into a CGI program, then execute it from pl/sql using utl_http.request.

  • Create "dynamic" statements in a stored procedure

    hello
    in my stored procedure I need to write a statement like this:
    FUNCTION myfunct (mytable IN VARCHAR2)
    BEGIN
    EXECUTE IMMEDIATE
    'SELECT COUNT(*)
    INTO myvar
    FROM ' || mytable ||
    'WHERE mycol = ' || currval;
    In short I need to create a sort of "dynamic" statement in which the tablename (nad other...) is a variable....
    but I do not guess it's ok...
    How can I do?

    Hi,
    With dyanmic SQL, the INTO clause is part of the EXECUTE IMMEDIATE statement, not the query.
    Try something like this:
    CREATE OR REPLACE FUNCTION     myfunct
    (       mytable       IN     VARCHAR2
    RETURN     PLS_INTEGER
    IS
         return_num     PLS_INTEGER;
         sql_txt          VARCHAR2 (1000);
    BEGIN
         sql_txt := 'SELECT  COUNT (*)'
              || ' FROM ' || mytable;
         dbms_output.put_line (sql_txt || ' = sql_txt in myfunct');
    --     EXECUTE IMMEDIATE sql_txt INTO return_num;
         RETURN     return_num;
    END     myfunct
    /It's a good idea to develop dynamic SQL as shown above; putting the dynamic statement into a variable that can easily be displayed for debugging.
    When it looks right, then un-comment the EXECUTE IMMEDAITE statement.
    Before moving the code into Production, comment out (or remove) the put_line statement.

  • Truncate statement in a stored procedure

    How can I execute a DDL statement, TRUNCATE TABLE table_name, from a stored procedure. In fact, I have tried the following:
    execute immediate ' truncate table table_name ';
    but it doesn't work. Do you have any ideas.
    The Oracle version is 7.3.
    Thanks in advance.

    The syntax for using dbms_sql is
    DECLARE
    v_cur INTEGER;
    v_ret INTEGER;
    BEGIN
    v_cur := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(v_cur, 'TRUNCATE TABLE your_tab', dbms_sql.v7);
    v_ret := DBMS_SQL.EXECUTE(v_cur);
    DBMS_SQL.CLOSE_CURSOR(v_cur);
    END;
    It's usually worth puting this in a stored procedure and passing the DDL statement in as a parameter, saves you having to type all this out everytime.
    If you don't have the dbms_sql package installed, the scripts are usually found under rdbms/admin

  • DDL statement/s in stored procedures (FUNCTION)

    Hello all,
    I was trying to create a small function that tests keywords on the basis of successful/failed table creation. If a table can be created with a keyword as identifier, it is a non-reserved keyword, if table creation fails, it is a reserved keyword:
    CREATE OR REPLACE FUNCTION createTableForKeyword (keyword VARCHAR) RETURN BOOLEAN IS
    BEGIN
    CREATE TABLE keyword (x NUMBER);
    -- if no exception occurred, table creation succeeded
    DROP TABLE keyword; drop it
    RETURN FALSE; -- FALSE means non-reserved
    EXCEPTION
    WHEN OTHERS THEN
    -- if exception occurred, table creation failed
    RETURN TRUE; -- TRUE means reserved
    END createTableForKeyword;
    This would have been my first PL/SQL program, but I get the following error:
    PLS-00103: Found symbol "CREATE" when expecting one of:
    begin case declare exit ................
    .............. merge pipe
    I had to translate the error message from German, but it should suffice. Obviously DDL statements in functions are not allowed. How do I solve my problem then, given a table that has one column containing the keyword?:
    CREATE TABLE Keywords (keyword VARCHAR(30));
    I was looking too call this function from a loop, but how would I do this without a function? How do I capture table creation fails without exceptions in functions?
    TIA
    Karsten

    To run DDL inside stored procedure you must use Dynamic SQL. Use EXECUTE IMMEDIATE
    To see if a word is a reserved word just query V$RESERVED_WORDS
    Thanks,
    Karthick.

  • Rollback of JDBC Statement on error - Stored Procedure

    Hi All,
    We are using the JBDC receiver adapter for inserting the record and for that we are using the Strored Procedure and we have N number of the records for insertion in a single mapping so, we have given the occurence of the Statement 1 : unbounded as, multiple statement will be executed so, my query is if one of statement fails because of some error(Mapping error or data error) what will happen to the statement which are already executed, do they rollback? or it is not possible in case of stored procedure?
    Regards,
    Gaurav

    Hi,
    This is one of the solution but i guess there is one more issue, if we have 10 statements and third statement shows error and Stored Exception exception branch is able to catch then it will rollback the previous statement but can we able to restrict another 7 pending statement for execution or not?
    Regards,
    Gaurav

  • Got error when use case statement in oracle stored procedure

    Hi,
    I have a query like:
    select merchant_id,
    case
    when product_type='K' then 'Production'
    when product_carrier='UC' THEN 'Shipping'
    end the_type
    from product_tbl
    where merchant_id=10114
    It works fine. But as soon as I put it into a stored procedure, I got error like:
    Encountered the symbol "CASE" when expecting one of the following:
    ( - + mod null <an identifier>
    Please help!

    Oracle 8i doesn't support CASE into PL/SQL, so as Kamal said, create a view with the CASE, and use this view into your PL/SQL.
    Nicolas.
    And an example here :
    Re: Execute Immediate doesnot work in 8i (8.1.7) and Ref Cursor not exec qu
    Sorry Kamal.
    Message was edited by:
    N. Gasparotto

Maybe you are looking for