EXECUTE IMMEDIATE call to procedure

need help on this piece of code.
1. lv_rec is a record of a table temp1 from which i need to validate lv_code.
2. The package1.proc_get_rec procedure has an IN OUT record parameter which is %ROWTYPE of the table in which the code exists.
3. lv_err_msg_out parameter will hold an error message if validation fails.
4. i need dynamic validation here because the table temp1(where code exists) and the package(needed to be called to validate the code) i am calling is residing in a defferent module.
declare
lv_plsql_block varchar2(1000);
lv_code :='B';
lv_rec temp1%ROWTYPE;
lv_err_msg_inout varchar2(100);
begin
lv_plsql_block := ' BEGIN package1.proc_get_rec(:1, :2, :3, :4); END;';
EXECUTE IMMEDIATE lv_plsql_block USING
lv_code,
SYSDATE,
IN OUT lv_rec,
IN OUT lv_err_msg_inout;
dbms_output.put_line('Err msg is '||lv_err_msg_inout);
end;
When i execute the above piece of code, i get the following error message:
Oracle Error :: PLS-00457 expressions have to be of SQL types
Is there any workaround for this problem??
Thanks in advance
Dodsferd

There is a procedure proc_get_rec which uses a %ROWTYPE of a table.
This procedure and table temp1 might exist or might not exist in the database based on the type of installation of the product
Now I cannot directly execute the above procedure because the table temp1 might exist or not.
So I am using dynamic SQL to make sure that there are no compilation errors.
In Dynamic SQL I am not able to pass the %ROWTYPE parameter of the procedure dynamically.
Kindly suggest some workarround for this.
Below is the sample of the procedure through which the dynamic SQL is called:
procedure P1 (lv_code varchar2(10))
is
lv_plsql_block varchar2(1000);
lv_rec temp1%ROWTYPE;
lv_err_msg_inout varchar2(100);
begin
lv_plsql_block := ' BEGIN package1.proc_get_rec(:1, :2, :3, :4); END;';
EXECUTE IMMEDIATE lv_plsql_block USING
lv_code,
SYSDATE,
IN OUT lv_rec,
IN OUT lv_err_msg_inout;
dbms_output.put_line('Err msg is '||lv_err_msg_inout);
end P1;

Similar Messages

  • Execute immediate for stored procedure with out parameter

    Hi,
    I have problem with dynamically executing the statement hope anyone can help me.
    I have a table which stores the procedure names. and procedure parameter values are stored on another column with parameter values coming from java side.
    I have to create a procedure that dynamically executes the procedure on table1 with the values from table 2.
    Now I'm getting real trouble to execute immediate this proc with parameters. I tried the DBMS_SQL package as well.
    Problem is you need to mention the OUT mode specifically for the out parameter. Can anybody plz help me with this issue??
    TABLE1_
    PROCESS_ID     PROC_NAME
    1      proc1(p1 IN number, p2 IN varchar2, p3 OUT varchar2)
    2     proc2(p1 IN number, p2 out varchar2, p3 OUT varchar2)
    TABLE2_
    PROCESS_ID     PROC_PARMS
    1     100, 'test', :return
    2     200, :return1, :return2
    Thank You

    826957 wrote:
    Hi,
    I have problem with dynamically executing the statement hope anyone can help me.
    I have a table which stores the procedure names. and procedure parameter values are stored on another column with parameter values coming from java side.
    I have to create a procedure that dynamically executes the procedure on table1 with the values from table 2.
    Now I'm getting real trouble to execute immediate this proc with parameters. I tried the DBMS_SQL package as well.
    Problem is you need to mention the OUT mode specifically for the out parameter. Can anybody plz help me with this issue??
    TABLE1_
    PROCESS_ID     PROC_NAME
    1      proc1(p1 IN number, p2 IN varchar2, p3 OUT varchar2)
    2     proc2(p1 IN number, p2 out varchar2, p3 OUT varchar2)
    TABLE2_
    PROCESS_ID     PROC_PARMS
    1     100, 'test', :return
    2     200, :return1, :return2
    Thank YouSounds like an appalling design and a nightmare waiting to happen.
    Why not have your Java just call the correct procedures directly?
    Such design smells badly of an entity attribute value modelling style of coding. Notoriously slow, notoriously buggy, notoriously hard to maintain, notoriously hard to read. It really shouldn't be done like that.

  • **URGENT** Problem using execute immediate in a procedure ...

    Hi all,
    I am writing this procedure
    create or replace procedure pr_test is
    begin
    EXECUTE IMMEDIATE 'CREATE or replace view test1 as select * from table_name';
    end ;
    when I execute this procedure even in the same schema who owns this table it gives me this message.
    BEGIN pr_test; END;
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "COLIS.PR_TEST", line 3
    ORA-06512: at line 1
    can any body lets me know the solution????
    Thanks in advance
    Take Care !
    Ghulam

    Thank you very much fellows.
    But I have reached at this point that one has to have create view privellege explicitly to create view using a dynamic sql statemetn. Actually I could create the view using SQL*Plus and every thing was working fine through SQL*Plus. But I granted the rights of create user from a user having DBA role.
    Anyways! Thank you very much for contributing this discussion. I really appreciate it.
    Ghulam Mustafa Butt

  • Urgent query related to execute immediate in a  procedure.

    hi,
    I want to create a table in the production database,within a procedure so I write query like:
    CREATE OR REPLACE PROCEDURE TEST
    IS
    BEGIN
    EXECUTE IMMEDIATE 'CREATE TABLE PE.BUD_VS_REV AS SELECT * FROM WH.WH_BUD_VS_REVNM1';
    END;
    but this is not working within the procedure it gives the
    ORA-01031: insufficient privileges.
    I already have asked to DBA he said that this user has all previlidges.
    one more thing if I write this query in an annonymous block like:
    BEGIN
    EXECUTE IMMEDIATE 'CREATE TABLE PE.BUD_VS_REV AS SELECT * FROM WH.WH_BUD_VS_REVNM1';
    END;
    its working well.
    can any buddy tellme what can be the reason,actually.
    Thanx
    Ritesh!

    Look this example:
    DBA >> CREATE USER LEO IDENTIFIED BY LEO
    2 /
    User created.
    DBA >> GRANT CREATE SESSION TO LEO
    2 /
    Grant succeeded.
    LEO >> CREATE OR REPLACE PROCEDURE TEST
    2 IS
    3 BEGIN
    4 EXECUTE IMMEDIATE 'CREATE TABLE PE.BUD_VS_REV AS SELECT * FROM WH.WH_BUD_VS
    _REVNM1';
    5 END;
    6 /
    CREATE OR REPLACE PROCEDURE TEST
    ERROR at line 1:
    ORA-01031: insufficient privileges
    DBA >> GRANT CREATE ANY PROCEDURE TO LEO
    2 /
    Grant succeeded.
    LEO >> CREATE OR REPLACE PROCEDURE TEST
    2 IS
    3 BEGIN
    4 EXECUTE IMMEDIATE 'CREATE TABLE PE.BUD_VS_REV AS SELECT * FROM WH.WH_BUD_VS
    _REVNM1';
    5 END;
    6 /
    Procedure created.

  • Using EXECUTE IMMEDIATE for DML

    What benefit is there to use EXECUTE IMMEDIATE for an UPDATE statement like the one below.
    EXECUTE IMMEDIATE 'UPDATE mytable SET bonus = v_bonus(i)
                       WHERE empid =:empid AND sal =:sal'
                              USING v_empid(n),v_sal(i);This UPDATE sql is not dynamically created. So is there any performance benefit associated with using
    EXECUTE IMMEDIATE for this UPDATE? Can't i just use a normal UPDATE without EXECUTE IMMEDIATE?

    Ran these same tests with SQL_Trace turned on, ran the trace files through tkprof and look at what it tells us:
    declare
    begin
    for i in 1 .. 100000 loop
    gso_prueba_a();
    end loop;
    end;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.07       0.08          0          0          0           1
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.07       0.08          0          0          0           1Now a slow one
    declare
    begin
    for i in 1 .. 100000 loop
    execute immediate 'call gso_prueba_b()';
    end loop;
    end;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1     36.07      36.54          0          0          0           1
    Fetch        0      0.00       0.00          0          0          0           0
    total        2     36.07      36.54          0          0          0           1but with this slow one, we see LOTS of recursive SQL - the 'call gso_prueba_b' is getting parsed a gazillion times with the resulting CPU consumption
    SQL ID : 1uu09hhqdp1yz
    call gso_prueba_b()
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute  99989      2.42       2.72          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total    99990      2.42       2.72          0          0          0           0
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 91     (recursive depth: 1)
    SQL ID : dcstr36r0vz0d
    select procedure#,procedurename,properties,itypeobj#
    from
    procedureinfo$ where obj#=:1 order by procedurename desc, overload# desc
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        2      0.00       0.00          0          4          0           1
    total        4      0.00       0.00          0          4          0           1Lots, lots more like this last one but having different SQL ID
    By wrapping the procedure call in a dynamically created anonymous block, you are incurring LOTS of overhead.
    What is it that you are trying to simulate.
    What are you trying to do?

  • Execute immediate ignoring hints

    Hi
    I'm looking for help about an unexpected behavior in oracle. I have a query that it is executed by a stored procedure, and this query has some hints to improve its performance. When I execute the procedure with sqlplus or any other tool, using "exec myprocedure;", the process took between 30 and 40 minutes to complete. But if I call this procedure inside another procedure with execute immediate command, it took more than 5 hours to complete.
    The procedure code is
    execute immediate 'begin '||proc||'; end;';
    proc is a variable that contain the procedure name to run
    It seems that oracle are ignoring my hints when it is executed by execute immediate command. In all tests that I've done I used the same user to connect.
    The version of oracle is 9.2.0
    Tks for any help

    > Why would you do this?
    Presumably he has a variable like "v_which_procedure" which could have the values 'RAISE_PAY()' or 'FIRE_ALL_EMPLOYEES()', and some logic that determines which to use.
    I would agree though that in general it would be better to structure things so that you are not in the position of slotting the name of a procedure dynamically into an EXECUTE IMMEDIATE call.
    I don't see how SQL inside a procedure would know that the procedure itself was called dynamically, so the fact that it seems to be performing differently is a bit of a mystery. I would want to be absolutely sure that that was actually what it was doing.

  • Problem with execute immediate code

    I have the following anonymous block:
    declare
    v_id_char varchar2(50) := '2072018827821663';
    trace_flg number := 0;
    v_exe_imm varchar2(500) := 'univdb.EML_CAMPUS_200605(v_id_char, trace_flg)';
    v_exe_imm2 varchar2(500) := 'univdb.EML_CAMPUS_200605(:v_id_char, :trace_flg)';
    begin
    --1) execute immediate v_exe_imm;
    --2) execute immediate v_exe_imm2 using v_id_char, trace_flg);
    univdb.EML_CAMPUS_200605(v_id_char, trace_flg);
    end;
    The compiled procedure that is getting called is defined like this:
    CREATE OR REPLACE PROCEDURE univdb.eml_campus_200605(
    hist_str IN VARCHAR2,
    trace_flg IN NUMBER := 0) IS ...
    As you might expect, when I execute the block without execute immediate it works.
    But either of the execute immediate statements results in ORA-00900: invalid SQL statment.
    I want to use execute immediate because the procedure that gets called will need to be dynamic.
    Help appreciated,
    ...elsa

    For me, thats crude if you have a procedure thats
    getting created dynamically.
    anyway, you could try a
    execute immediate ' begin ' || your_funny_proc || '
    end;';But for sure the whole stuff is very error prone.Actually, the procedure itself isn't getting built dynamically, only which procedure to call. It's really quite clever in my opinion.
    Anyway, I tried you suggestion:
    declare
    v_id_char varchar2(50) := '2072018827821663';
    trace_flg number := 0;
    v_exe_imm varchar2(500) := 'univdb.EML_CAMPUS_200605(v_id_char, trace_flg)';
    v_exe_imm2 varchar2(500) := 'univdb.EML_CAMPUS_200605(:v_id_char, :trace_flg)';
    begin
    execute immediate 'BEGIN ' || v_exe_imm || '; END;';
    --execute immediate v_exe_imm2 using v_id_char, trace_flg);
    --univdb.EML_CAMPUS_200605(v_id_char, trace_flg);
    end;
    and got
    ORA-06550: line 1, column 32:
    PLS-00201: identifier 'V_ID_CHAR' must be declared
    Did I misunderstand what you were trying for?

  • Problem to insert using execute immediate

    Have a procedure like this:
    create or replace procedure proc_set_category(
    VC_object_id IN number,
    VC_object IN varchar2,
    VC_category_id IN varchar2
    is
    sq varchar2(200);
    BEGIN
         sq:='INSERT INTO ' || VC_object ||'_category (' || VC_object || '_id,category_id) VALUES (' || VC_object_id || ',' || VC_category_id ||')';
         EXECUTE IMMEDIATE sq;
    END;
    Procedure created.
    but when i try to execute the following query it generates an error
    execute proc_set_category(1,'news','event')
    ERROR at line 1:
    ORA-00984: column not allowed here
    ORA-06512: at "SCOTT.PROC_SET_CATEGORY", line 10
    ORA-06512: at line 1
    I have a news_category table.where is the problem?

    sq:='INSERT INTO ' || VC_object ||'_category (' || VC_object || '_id,category_id) VALUES (' || VC_object_id || ',' || VC_category_id ||')';
    EXECUTE IMMEDIATE sq;
    execute immediate 'INSERT INTO ' || VC_object ||'_category (' || VC_object || '_id,category_id) VALUES (:1, :2)'
      using VC_object_id, VC_category_id;

  • EXECUTE IMMEDIATE NO PRIVALIGE

    No privilege to execute this statement ,but the current user is already has right to create sequence.
    EXECUTE IMMEDIATE(' CREATE SEQUENCE '||P_Sequance_Name||
                             ' START WITH '||P_Start_With||
                             ' MAXVALUE '||P_MaxValue||
                             ' MINVALUE '||P_MinValue||
                             ' '||P_CYCLE||
                             ' '||P_CACHE||
                             ' '||P_ORDER);

    If you trying to use EXECUTE IMMEDIATE in forms procedure - this is probably not a privilege problem.
    EXECUTE IMMEDIATE is is not supported in client side.
    Try to replace it with
    forms_ddl(' CREATE SEQUENCE '||P_Sequance_Name||
                                ' START WITH '||P_Start_With||
                                ' MAXVALUE   '||P_MaxValue||
                                ' MINVALUE   '||P_MinValue||
                                ' '||P_CYCLE||
                                ' '||P_CACHE||
                                ' '||P_ORDER);

  • Execute immediate issue while calling a procedure from plsql block

    Hi all,
    I have the following simple code ,my execute immediate is not working(I am pasting the error below as well)
    CREATE OR REPLACE PROCEDURE CALL_RAHUL_PROCEDURES
    AS
    strng varchar2(1000);
    BEGIN
    for i in (select proc_name,flag,id from rahul_procedures order by id)
    loop
    if (i.flag = 'Y')
    then
    strng := 'exec '||i.proc_name||'(''rahul'')';
    dbms_output.put_line(strng);
    execute immediate strng;
    end if;
    end loop;
    END CALL_RAHUL_PROCEDURES;
    Error:
    Connecting to the database INQDWD.
    ORA-00900: invalid SQL statement
    ORA-06512: at "ETLADMIN.CALL_RAHUL_PROCEDURES", line 17
    ORA-06512: at line 2
    exec RAHUL_HELLO_WORLD2('rahul');
    Process exited.
    Disconnecting from the database INQDWD.
    data in rahul_procedures table :
    Proc_name flag Id
    RAHUL_HELLO_WORLD     N     1
    RAHUL_HELLO_WORLD2     Y     2
    RAHUL_HELLO_WORLD     N     3
    RAHUL_HELLO_WORLD3     N     4
    please help.
    Regards
    Rahul

    Mac_Freak_Rahul wrote:
    Well I have to call 26 procedures one by one and the names of the procedures would be in a table'rahul_procedures' Which is 100% wrong.
    Data is stored in tables, program code is stored in procedures or view defintions.
    http://en.wikipedia.org/wiki/Data_%28computing%29
    >
    Data vs programs
    Typically, different files are used to store programs vs data. Executable files contain programs; all other files are data files.
    >
    So you have just violated the primary distinction between data and program code.
    I dont find anything strange in my question,Only because you do not appear to know what you are doing or the difference between data and program code.
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1943344500346351703
    >
    ugh, what an ugly "design". I can see your life will be full of performance issues, strange 'bugs', and other unpleasant side effects. I mean, it all looks "so cool", but it'll be a nightmare to maintain and enhance.
    but then you have the issue of binds, which will be intractable. You'd have to know the binds at compile time, but you have hidden all of your sql in a magic generic table - so you cannot possibly know your binds at compile time.
    I would suggest you discard all of this code (I am DEAD SERIOUS) and start over. This is a bad idea from the get go. Or at least do me a favor and do not use plsql (you make it look like a good database implementation, but it isn't)
    The objective here is to store SQL Statements in a Table(a sql repository) and just call the required SQL from the application using the sqlid using the sql_execute procedure. ...
    CHANGE YOUR OBJECTIVE.
    How about this for a good objective:
    the objective here is to store sql statement in a plsql routine (a sql repository, you call a procedure and we run sql) and just call the required sql form the applicatoin using the STORED PROCEDURE
    sorry, can I think of hacks to get you going? yes, application contexts come to mind - a fixed number of binds comes to mind. Am I going to work them out? No - it is the wrong way to approach a database application.

  • Execute immediate a procedure call

    Hi,
    I need some help, can some one EXPLAIN why its failing when i don't specify the test_proc in spec.
    i know this is not the right way of doing things. want to know why i need to specify the procedure name in spec.
    SQL> select * from v$version;
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production   
    PL/SQL Release 11.2.0.2.0 - Production                                         
    CORE 11.2.0.2.0 Production                                                     
    TNS for Linux: Version 11.2.0.2.0 - Production                                 
    NLSRTL Version 11.2.0.2.0 - Production                                         
    SQL> CREATE OR REPLACE PACKAGE PkgTest AS
      2 
      3    --PROCEDURE test_proc;
      4    PROCEDURE run_proc;
      5  END PkgTest;
      6  /
    Package created.
    SQL>
    SQL>
    SQL> CREATE OR REPLACE PACKAGE BODY PkgTest AS
      2 
      3  PROCEDURE test_proc IS
      4    BEGIN
      5      dbms_output.put_line(' Test Proc');
      6  END test_proc;
      7 
      8  PROCEDURE run_proc IS
      9  BEGIN
    10      EXECUTE IMMEDIATE 'begin  PkgTest.test_proc; end;';
    11  END run_proc;
    12  END PkgTest;
    13  /
    Package body created.
    SQL> exec pkgtest.run_proc;
    BEGIN pkgtest.run_proc; END;
    ERROR at line 1:
    ORA-06550: line 1, column 16:
    PLS-00302: component 'TEST_PROC' must be declared
    ORA-06550: line 1, column 8:
    PL/SQL: Statement ignored
    ORA-06512: at "MPIEFP_DEV.PKGTEST", line 10
    ORA-06512: at line 1
    SQL> CREATE OR REPLACE PACKAGE PkgTest AS
      2 
      3    PROCEDURE test_proc;
      4    PROCEDURE run_proc;
      5  END PkgTest;
      6  /
    Package created.
    SQL> exec pkgtest.run_proc;
    Test Proc                                                                      
    PL/SQL procedure successfully completed.
    SQL> spool off

    Hi,
    If you tried to run this command from PL/SQL
    SQL>  EXEC  PkgTest.test_proc;
    do you understand why it would fail?  It fails in EXECUTE IMMEDIATE for the same reason.
    When you use EXECUTE IMMEDIATE, Oracle runs the dynamic command in a new, separate environment.  It knows nothing about the context from which it was called.  In particular, it doesn't know if it was called from inside a package or not, so procedures that are private to that package can't be called.
    Do you really need to use EXECUTE IMMEDIATE?  You obviously don't in the simple test scenario you posted, but I assume your real package is much more complicated.
    Why not simply include test_proc in the package spec?
    Is the problem that end users, who are allowed to cal run_proc, are not supposed to call test_proc direrctly?  If so, put them in different pacakges.  Declare test_proc in the spec of its package, but don't grant privileges on the package that end users.

  • Java Stored Procedure in EXECUTE IMMEDIATE

    Hi,
    I need advice for the following.
    I'm on Oracle 11g R2. I'm testing application in Oracle 11gR1 and R2 and Oracle Express.
    Purpose is to generate XML reports.
    I have PLSQL Stored Procedure which does that, but since there is bug in Oracle11gR2 related to XMLTRANSFORM I have and Java Stored Procedure which is workaround. They are both compiled, valid etc.
    Java class is :
    import java.io.PrintWriter;
    import java.io.Writer;
    import oracle.xml.parser.v2.DOMParser;
    import oracle.xml.parser.v2.XMLDocument;
    import oracle.xml.parser.v2.XSLProcessor;
    import oracle.xml.parser.v2.XSLStylesheet;
    * This class is used as Java stored procedure
    * There is a bug on Oracle11gR2, related to the limitation on the number of style sheet instructions
    * This stored procedure is workaround when PLSQL code can not be used.
    * File must not have package, otherwise is wrongly compiled in DB
    public class JavaXslt {
         public static void XMLTtransform(oracle.sql.CLOB xmlInput,oracle.sql.CLOB xslInput,oracle.sql.CLOB output) throws Exception{
              DOMParser parser;
              XMLDocument xml;
              XMLDocument xsldoc;
              try{
                   parser = new DOMParser();
                   parser.parse(xmlInput.getCharacterStream());
                   xml = parser.getDocument();
                   parser.parse(xslInput.getCharacterStream());
                   xsldoc = parser.getDocument();
                   XSLProcessor processor = new XSLProcessor();
                   XSLStylesheet xsl = processor.newXSLStylesheet(xsldoc);
                   Writer w = output.setCharacterStream(1L);
                   PrintWriter pw = new PrintWriter(w);
                   processor.processXSL(xsl, xml, pw);
              }catch (Exception ex){
                   throw ex;
    PROCEDURE Java_XmlTransform (xml CLOB, xslt CLOB, output CLOB) AS LANGUAGE JAVA
    NAME 'JavaXslt.XMLTtransform(oracle.sql.CLOB, oracle.sql.CLOB, oracle.sql.CLOB)';
    I'm calling Java stored procedure from PLSQL Stored procedure (if it is Oracle11gR2) like that :
    Java_Proc.Java_XmlTransform(inputXML, xslt, res);
    So till here everything works ok. XSLT as applied and output XML (res) is OK.
    But when Oracle Express is used Java is out of the question, so there is no Java stored procedure. Howewer PLSQL Stored procedure is still needed.
    So I had to put call to Java Stored procedure in EXECUTE IMMEDIATE statement in order to compile to PLSQL package.
    But when I do that :
    EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING inputXML, xslt, res;
    result value CLOB (res) has zero length...
    What am I missing? Should i set return value to Java class?
    Hope my explanations are clear though.
    Thanks

    Hi odie_63,
    Thanks for quick response.
    I didn't clearly explained.
    When using Oracle 11gR1 and Oracle Express I'm using only PLSQL Procedure.
    When using Oracle 11gR2 i have to use Java Stored procedure because there is documented bug in R2.
    That's why i have to use EXECUTE IMMEDIATE. I don't know which version is the client DB and whether there is or no Java procedures.
    I did tried
    EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, OUT res; and the result was ORA-06537: OUT bind variable bound to an IN position
    When using IN OUT for last parameter i.e.
    EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, IN OUT res;
    there is no exception, but still DBMS_LOB.getlength(res) = 0
    Thanks

  • How to use Execute Immediate to execute a procedure and return a cursor?

    The procedure name is unknown until run time so I have to use Execute immediate to execute the procedure, the procedure return a cursor, but I can't figure out the right syntax to pass the cursor out.
    To simplify the issue here, I create two procedures as examples.Assume I have a procedure called XDTest:
         p_cur OUT SYS_REFCURSOR
    IS
    BEGIN
    OPEN p_cur FOR
    Select * from dummy_table;
    END XDTest;
    In another procedure, I want to use Execute Immediate to execute XDTest and obtain the result that return from the cursor into a local cursor so I can process the records:
         p_cur OUT SYS_REFCURSOR
    IS
    l_cur SYS_REFCURSOR;
    BEGIN
    execute immediate 'BEGIN XDTest (:1); END;' using OUT l_cur;
    END XDTest2;
    However, this is not working, I get ORA-03113: end-of-file on communication channel error.
    What syntax should I use here?
    Cheers

    well...
    I update the XDTest2 procedure as below but when execute it get exceptions.I think the v_sqlstmt syntax is wrong, but I don't know what meant to be correct, please give some suggestions .
    Cheers
    -------------------- XDTest procedure --------------------------------------------------
         p_cur OUT SYS_REFCURSOR
    --AUTHID CURRENT_USER
    IS
    BEGIN
    OPEN p_cur FOR
    Select Table_Name from USER_Tables;
    END XDTest;
    -------------------- XDTest2 procedure --------------------------------------------------
         p_cur OUT SYS_REFCURSOR
    IS
    TYPE T1 IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER ;
    v_sqlstmt varchar2(1000):=null;
    v_cursor number;
    x_num number;
    LN$Lig number := 0 ;
    LN$MaxCol number := 0 ;
    t T1 ;
    v VARCHAR2(4000) ;
    userTb User_Tables%ROWTYPE;
    l_cur number;
    BEGIN
    LN$Lig := 0 ;
    LN$MaxCol := 1 ;
    --OPEN p_cur FOR
    --execute immediate 'BEGIN XDTest (:1); END;' using OUT l_cur;
    v_cursor:=dbms_sql.open_cursor;
    v_sqlstmt:='begin :p_cur:="XDTest"(); END; ';
    dbms_sql.parse(v_cursor,v_sqlstmt,DBMS_SQL.NATIVE);
    dbms_sql.bind_variable(v_cursor,':p_cur',l_cur);
    dbms_output.put_line('1');
    -- Define the columns --
    dbms_sql.DEFINE_COLUMN(v_cursor, 1, userTb.Table_Name, 30);
    x_num:=dbms_sql.execute(v_cursor);
    dbms_output.put_line('2');
    -- Fetch the rows from the source query --
    LOOP
    IF dbms_sql.FETCH_ROWS(v_cursor)>0 THEN
    -- get column values of the row --
    dbms_sql.COLUMN_VALUE(v_cursor, 1,userTb.Table_Name);
    dbms_output.put_line(userTb.Table_Name);
    ELSE
    -- No more rows --
    EXIT;
    END IF;
    END LOOP;
    dbms_sql.close_cursor(v_cursor);
    END XDTest2;
    ---------------------- Error when execute ------------------------------------------------
    1
    BEGIN DevD0DB.XDTest2(:l_cur); END;
    ERROR at line 1:
    ORA-01007: variable not in select list
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 1010
    ORA-06512: at "SYS.DBMS_SQL", line 212
    ORA-06512: at "DEVD0DB.XDTEST2", line 35
    ORA-06512: at line 1
    ----------------------------------------------------------------------------------------------------

  • How to execute a statement in forms procedure like SQL EXECUTE IMMEDIATE

    Hi to all,
    In a form I have created this procedure:
    PROCEDURE insert_rows (
    tbName IN VARCHAR2,
    list_of_fields IN VARCHAR2,
    origin_table IN VARCHAR2,
    wCondition IN VARCHAR2 DEFAULT NULL)
    IS
    where_clause VARCHAR2 (2000) := ' WHERE ' || wCondition ;
    table_to_fill VARCHAR2 (30);
    BEGIN
    -- Exist the table ?
    SELECT OBJECT_NAME INTO table_to_fill FROM USER_OBJECTS
    WHERE OBJECT_NAME = UPPER(origin_table) AND OBJECT_TYPE = 'TABLE' ;
    IF wCondition IS NULL THEN
    where_clause := NULL;
    END IF ;
    EXECUTE IMMEDIATE 'INSERT INTO ' || table_to_fill || ' SELECT ' || list_of_fields || ' FROM ' || origin_table || where_clause ;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    -- Here the Alert
    END;
    But, when I compile this error is displayed:
    Function not supported from client side application corresponding to SQL statement EXECUTE IMMEDIATE
    How can to correct this script for my form ?
    I hope in Your help.
    Best Regards
    Gaetano

    You have two options:
    1)To create this procedure in database
    2)Yo use the forms built-in FORMS_DDL instead of execute immediate , altering the one provided
    Sim

  • Problem wile EXECUTE IMMEDIATE DDL statement in procedure

    Hi ,
    This is my procedure and it's getting compiled but while executing procedure getting this error,
    can anyone please tell me how to fix this?
    create or replace procedure construct_Table (name_table IN VARCHAR2)
    IS
    v_tab_name varchar2(40):=NULL;
    v_sql_Stmt varchar2(32767) := NULL;
    finalquery varchar2(32767) :=NULL;
    cursor tp is
    select COLUMN_NAME,DATA_TYPE,DATA_PRECISION,CHAR_LENGTH  from all_tab_cols where table_name=name_table;
    BEGIN
    begin
    select TABLE_NAME into v_tab_name from user_tables where table_name=name_table;
    EXCEPTION
    WHEN no_Data_found
    THEN
    DBMS_OUTPUT.PUT_LINE('No such table exist');
    end;
    if(v_tab_name IS NOT NULL)then
    finalquery := 'CREATE TABLE '||v_tab_name||'_DUMMY (';
       FOR I IN tp LOOP
       if(I.data_type='VARCHAR2') then
       v_sql_stmt := finalquery ||I.column_name||' '||I.data_type||'('||I.char_length||') ';
       elsif(I.data_type='NUMBER') then
       v_sql_stmt := finalquery ||I.column_name||' '||I.data_type||'('||I.DATA_PRECISION ||') ';
       else
       v_sql_stmt := finalquery ||I.column_name||' '||I.data_type ;
       end if;
       finalquery := v_sql_stmt || ',';
       END LOOP;
       finalquery := SUBSTR(finalquery,1,LENGTH(finalquery) - 1)||')';
       dbms_output.put_line(finalquery);
       EXECUTE IMMEDIATE'grant create any table to cmsuser';
       EXECUTE IMMEDIATE finalquery;
    end if; 
    END;
    /This is the error I am getting
    Error starting at line 1 in command:
    begin
    construct_Table ('EMP');
    end;
    Error report:
    ORA-01031: insufficient privileges
    ORA-06512: at "CMSUSER.CONSTRUCT_TABLE", line 30
    ORA-06512: at line 2
    01031. 00000 -  "insufficient privileges"
    *Cause:    An attempt was made to change the current username or password
               without the appropriate privilege. This error also occurs if
               attempting to install a database without the necessary operating
               system privileges.
               When Trusted Oracle is configure in DBMS MAC, this error may occur
               if the user was granted the necessary privilege at a higher label
               than the current login.
    *Action:   Ask the database administrator to perform the operation or grant
               the required privileges.
               For Trusted Oracle users getting this error although granted the
               the appropriate privilege at a higher label, ask the database
               administrator to regrant the privilege at the appropriate label.Thanks ,
    Deekay.

    Deekay,
    If you grant create table privilege and create table in the same procedure, then how you will differentiate that which user you granted the privilege and in which schema, you are creating the table. Here, you are granting to "cmuser", but in the same schema, you are creating the table also. How can a user grant privilege to himself?
    Login as DBA, grant create any table privilege to "cmuser" from dba. Then, you can execute you procedure in "cmuser" schema.

Maybe you are looking for