Execute Immediat for Cursor

Dear all
can i use Execute Immediate For a Cursor..
for example :-
create or replace procedure P_MAPPING(iaap_name varchar2)
IS
CUR_C1 varchar2(200);
CUR_C2 varchar2(200);
Cur_c1 := 'cursor C1 is
             select recid, xmlrecord
             from'|| OSRC_TAB;   *---Here How can i pass the value which i am getting from the Procedure Below(P_PAPULATE_TAB)*
Cur_c2 := 'Cursor C2 is
           Select column_name,Seq_no
           from TMP_MAP_TAB2
           Where Appl_name = '||ODEST_TAB;*---Here How can i pass the value which i am getting from the Procedure Below(P_PAPULATE_TAB_)*
   Type array_type IS TABLE of varchar2(1000) index by binary_integer;
   OSRC_TAB varchar2(100);
   ODEST_TAB varchar2(100);
begin
  P_PAPULATE_TAB(IAAP_NAME,OSRC_TAB,ODEST_TAB);
  execute immediate CUR_C1 using OSRC_TAB; 
  execute immediate CUR_C2 using ODEST_TAB;I want to pass the OSRC_TAB,ODEST_TAB which ore the OUT parameters in the procedure In the Cursor..
Is it possible ?

Hi,
You can try this using sys_refcursor as like below
cur_c1 VARCHAR2(200);
cur_c2 VARCHAR2(200);
osrc_tab VARCHAR2(100);
odest_tab VARCHAR2(100);
l_sys_ref_1 sys_refcursor;
l_sys_ref_2 sys_refcursor;
BEGIN
P_PAPULATE_TAB(IAAP_NAME,OSRC_TAB,ODEST_TAB);
cur_c1 := 'SELECT recid, xmlrecord
FROM'|| osrc_tab;
cur_c2 := ' SELECT column_name,Seq_no
FROM tmp_map_tab2
WHERE appl_name = '||odest_tab;
OPEN l_sys_ref_1
FOR cur_c1;
OPEN l_sys_ref_2
FOR cur_c2;
Thanks

Similar Messages

  • 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?

  • How to use execute immediate for character string value 300

    how to use execute immediate for character string value > 300 , the parameter for this would be passed.
    Case 1: When length = 300
    declare
    str1 varchar2(20) := 'select * from dual';
    str2 varchar2(20) := ' union ';
    result varchar2(300);
    begin
    result := str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || ' ';
    dbms_output.put_line('length : '|| length(result));
    execute immediate result;
    end;
    /SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
    length : 300
    PL/SQL procedure successfully completed.
    Case 2: When length > 300 ( 301)
    SQL> set serveroutput on size 2000;
    declare
    str1 varchar2(20) := 'select * from dual';
    str2 varchar2(20) := ' union ';
    result varchar2(300);
    begin
    result := str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || str2 ||
    str1 || ' ';
    dbms_output.put_line('length : '|| length(result));
    execute immediate result;
    end;
    /SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at line 6

    result varchar2(300);Answer shouldn't be here ? In the greater variable ?
    Nicolas.

  • 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.

  • Using execute immediate for select

    Hi all,
    i am writing a procedure as follows:
    create or replace procedure ( run_yr_mo in number) as
    v_count number := 0;
    begin
    execute immediate 'select count(*)
    from all_tables
    where owner = ''MGR''
    and table_name = ''FC_PR_'''||run_yr_mo||''
    into v_count;
    dbms_output.put_line(v_count);
    end;
    this is returning me an error at the execute immediate.
    run_yr_mo = 200912
    Can someone help me out with this.
    Thanks

    Just to show it working:
    SQL> create or replace procedure myproc ( run_yr_mo in number) as
      2   v_count number := 0;
      3  begin
      4    select count(*)
      5    into v_count
      6    from all_tables
      7    where owner = 'MGR'
      8    and table_name = 'FC_PR_'||to_char(run_yr_mo,'fm999999');
      9
    10    dbms_output.put_line(v_count);
    11  end;
    12  /
    Procedure created.
    SQL> set serverout on
    SQL> exec myproc('200910');
    0
    PL/SQL procedure successfully completed.
    SQL>

  • Need suggestion on PLSQL Create and EXECUTE IMMEDIATE

    Most of you already know plsql doesn't like create table, so we have to use EXECUTE IMMEDIATE for creating table. What if I want to see if the table exist, if not then create the table, later I will insert data into that table.
    My problem is it returned me the error saying I am try to insert into a non existing table when trying to compile my code. I think plsql doesn't pick up the execute statement.
    what I did is, both create and insert are executed by using EXECUTE IMMEDIATE. Anyone have such experience before and willing to share your knowledge?
    PS: I am having same problem for creating sequence as well.

    I think plsql doesn't pick up the execute statement.Since it is a runtime instruction, it will pick it up at runtime. but to be able to run, it needs to compile the code and in order to compile (so it can run) the code it needs that table/sequence you are referencing to exist already. So, you need to run the code to get the table and run needs to compile the code and compile needs the table to compile. can't go from here to there when you try to mix dynamic sql with static sql on the same object within the same program unit (or dependent units).

  • Execute Immediate in Oracle 10g

    Hi , I have a small doubt regarding execute immediate.
    As per my knowledge we use execute immediate for writing DDL(create,truncate,...) statements to execute in the procedure or function.
    But i have seen in my organization , some of the senior people(already left organization) used to write inserts , updates , deletes also in execute immediate even there is not much dynamic logic involved.
    But as per my knowledge execute immediate can be badly used by most of the hackers with SQL injection I guess!!!!!
    Is there any reason that they use execute immediate instead of writing the code directly??? Or is there any advantage in writing like this.???

    Using execute immediate to create tables and other DDL is fundamentally undesirable, and should be avoided at all cost.
    The use of execute immediate you seem to outline, should be avoided too. Apparently those seniors were unaware of the goal of PL/SQL and the disadvantage of execute immediate.
    If I could vote to remove execute immediate from PL/SQL, I would be immediately in favor, especially in packages, procedures and functions,as they are stored, which means pre-compiled.
    Sybrand Bakker
    Senior Oracle DBA

  • 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.

  • EXECUTE IMMEDIATE within Procedure doesn't work!!

    Hi,
    I have a code in which the procedure is successfully created, but when I try to check if the table TEST_TABLE is created (ex, DESC TEST_TABLE) it generates an error:
    ORA-04043: object TEST_TABLE does not exist
    Which means that my EXECUTE IMMEDIATE didn't work within the procedure for some reason, while it works perfectly alone without the procedure!!
    Hope you help me with this..
    Here's the my code:
    CREATE OR REPLACE PROCEDURE TEST_IMM1
    AS
    BEGIN
    EXECUTE IMMEDIATE ' CREATE TABLE TEST_TABLE (ITEM_DESC VARCHAR2(10))';
    END;
    --Procedure created.
    DESC TEST_TABLE
    ERROR:
    ORA-04043: object TEST_TABLE does not exist

    user11921409 wrote:
    Thanks a lot Ahmed, yes it worked after executing the procedure and table is created. But that's only one part of the problem, in which after dynamically creating the table TEST_TABLE, I should be able to insert data to it such as:
    CREATE OR REPLACE PROCEDURE TEST_IMM1
    AS
    BEGIN
    EXECUTE IMMEDIATE ' CREATE TABLE TEST_TABLE (ITEM_DESC VARCHAR2(10))';
    END;
    --Procedure created.
    CREATE OR REPLACE PROCEDURE INSERT_TEST_TABLE
    AS
    BEGIN
    TEST_IMM1;
    INSERT INTO TEST_TABLE VALUES ('A');
    END;
    --Warning: Procedure created with compilation errors.
    PL/SQL: SQL Statement ignored
    PL/SQL: ORA-00942: table or view does not exist
    Can you tell me how to use INSERT with EXECUTE IMMEDIATE.
    Thanks :)Just as an FYI, this is really not a good methodology to program in Oracle. If you're doing this for purely learning purposes then it's less 'bad', but if you plan on programming as a career in Oracle, this isn't the method you'd want to adopt (i'll not say there is NEVER a case for something like this, but it's a small percentage of the typical use cases).
    You would do better to create a global temporary table if you need a table to muck around with in a session, or create a permanent table (likely not via procedures) and have it persist in the schema of your choice.
    Utilizing execute immediate for insert statements, especially without BIND VARIABLES, will create a sad day for your database.

  • Difference between regular update and update with execute immediate

    Hi everyone, I have seen some code where developers have executed insert and update statement using execute immediate.
    for example :
    execute immediate ('Update employees set employee_salary = :x');
    I can update record using the following statement where x is a number (salary)
    update employee
    set employee_salary = x;
    It works fine as well
    Whats the difference? and what way is recommended
    Thanks

    My guess is that sqlplus does a commit on exit:
    In session 1:
    SQL> create table test (col1 number);
    Table created.
    SQL> begin
      2    execute immediate 'insert into test values (1)';
      3  end;
      4  /
    PL/SQL procedure successfully completed.In session 2:
    SQL> select * from test;
    no rows selectedIn session 1:
    SQL> exec execute immediate 'insert into test values (2)';
    PL/SQL procedure successfully completed.In session 2:
    SQL> select * from test;
    no rows selectedIn session 1:
    SQL> disconnect
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, Oracle Label Security, OLAP and Data Mining optionsIn session 2:
    SQL> select * from test;
          COL1
             1
             2

  • Cursor in EXECUTE IMMEDIATE

    How to use cursor in EXECUTE IMMEDIATE command.
    i.e. I have a dynamic SELECT query where I will get huge records while using EXECUTE IMEDIATE command, which I want that to be in a cursor.
    Can I do this ? If yes how ?

    Hi, it works perferctly fine with me. Oracle version 10.2.0.4
    SQL> --create table t as select * from user_objects; ----->>> My mistake, there is no owner column in the table user_objects
    SQL> create table t as select * from all_objects;
    Table created.
    SQL> CREATE OR REPLACE PROCEDURE dynamic_table (
      2    table_name IN VARCHAR2,
      condition IN VARCHAR2 DEFAULT NULL) AS
      3    4    where_clause VARCHAR2(100) := ' WHERE ' || condition;
      5    v_table varchar2(30);
      6    type v_typet  is table of t%rowtype index by pls_integer;
      7    v_tableT v_typeT;
      8  BEGIN
      -- first make sure that the table actually exists; if not, raise an exception
      SELECT OBJECT_NAME INTO v_table FROM USER_OBJECTS
      9   10   11    where object_name = upper(table_name) and object_type = 'TABLE';
      if condition is null then where_clause := ' order by object_type'; end if;
    12   13    execute immediate 'SELECT * from ' || v_table || where_clause  bulk collect into v_tablet;
    14    for indx in 1..v_tablet.count loop
        dbms_output.put_line(v_tablet(indx).owner || ' ' || v_tablet(indx).status);
    15   16    end loop;
    17    EXCEPTION
    18    when no_data_found then
    19      dbms_output.put_line ('Invalid table: ' || table_name);
    20  end;
    21  /
    Procedure created.
    begin
      dynamic_table('T', '');
      --Enter the table name you want for the 1st parameter and the condition for the second parameter.
      --I think you just want to switch from tables where you want to select.
    end;
    /Edited by: Spongebob on May 25, 2010 1:33 PM

  • Creating cursor using Execute immediate

    I am trying to create one cursor using a for loop, but I am not able to do so, could you please help me with the approach to get it done.
    Here is the scenario:
    I have one table table_1,it contains 2 columns source_query , target_query.
    source_query and target_query are Select statements like source_query is Select name, age , valid from customer where customer_id=123456;
    I fetched the data from these columns into 2 strings
    select source_query into source_data from table_1;
    select target_query into target_data from table_1;
    Now out of these 2 I want to create 2 cursors, so that I can compare the column values one by one ( I am not using the  source minus target approach because of difference in the data type).
    I have to individually check the values.
    So here are the cursors:
    For source_data_value in ( EXECUTE immediate source_data)
    LOOP
    For target_data_value in (EXECUTE IMMEDIATE target_data)
    LOOP
    <executable statements>;
    END LOOP;
    END LOOP;
    But the cursor creation is failing in the procedure.
    Please let me know if it is possible to create a cursor using the execute immediate , if not what approach I should use other than this?

    Why exactly you are doing this inside a procedure. You can take the SQL's out and write a simple query to retrieve the data. Anyways, to work it out in a procedure, I can think of the below solution. I am trying to do away with Execute Immediate and use REF cursor. Please note that this is untested and just a try to present a possible solution which can be changed to implement your original requirement. I haven't done anything sort of this before, so if this approach doesn't approach, kindly ignore
    DECLARE
       TYPE TempTyp IS REF CURSOR;
       temp_cv   TempTyp;
      temp_cv_2 Temptyp;
       emp_rec  emp%ROWTYPE;
       source_data VARCHAR2(200);
         target_data  VARCHAR2(200);
       BEGIN
       source_data:= 'SELECT * FROM source tablej';
       target_Date :='select * from target table';
       OPEN temp_cv FOR source_data;
       LOOP
          FETCH temp_cv INTO emp_rec;
          EXIT WHEN emp_cv%NOTFOUND;
            OPEN   temp_cv_2 FOR target_data;
              FETCH Temp_cv_2 into  emp_rec  emp%ROWTYPE
                   loop
                        < And then your comparisons here >
         END LOOP:
         CLOST TEMP_CV_2;
       END LOOP;
       CLOSE temp_cv;
    END;
    Ishan

  • 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
    ----------------------------------------------------------------------------------------------------

  • Equivalent  for execute immediate command in maxdb

    hi all,
    like in oracle for executing the sql_query, we have execute immediate command.
    for e.g.. in oracle
    L_SQL ='SELECT * FROM EMP';
    EXECUTE IMMEDIATE L_SQL;
    what will be the command for execute immediate in MaxDB??
    like in MaxDB
    L_SQL = 'SELECT * FROM EMP';
    Now How can i execute the above l_sql variable in MaxDB.
    thanks, Bhupinder

    Hi Bhupinder,
    the following code snippet should do the job
    [code]
    CREATE DBPROC EXAMPLE
    AS
    VAR statement1 char(100);
    SET statement1 = 'SELECT * from DBA.DUAL';
    TRY
        EXECUTE statement1;
    CATCH IF $rc <> 100
         THEN STOP ($rc, 'unexpected error');
    [/code]
    Best regards,
    Marco

  • How to pass a sequence by 'using' for execute immediate

    how i can pass a sequence.nxlval as a parameter through using , here is my code looks like
    sql_string is -> insert into some_tab (col1,col2, ....) (select col1,:passed_seq,......) where .... (i want to insert sequence values for col2)
    and i am calling this as
    passed_seq := 'seq_'||some_dynamic_num||'.nextval' ( in my db there will be sequences with the formed string like seq_10.nextval)
    EXECUTE IMMEDIATE sql_string using passes_seq;
    if i am doing like this i am getting
    Error : -1722:ORA-01722: invalid number seq_10.nextval
    Edited by: DIVI on Jan 8, 2013 7:40 AM

    Hi,
    I hope you have created sequence as below
    SQL>
    SQL> CREATE SEQUENCE seq
      2  MINVALUE 1
      3  START WITH     1
      4  INCREMENT BY   1
      5  NOCACHE
      6  NOCYCLE;
    Sequence created.
    SQL>
    SQL> SELECT * FROM TEST1;
         EMPNO EMPTYPE              EMP_ADDRESS              SALARY     DEPTNO
             1 HR                   MUMBAI                    10000         10
             2 ADMIN                THANE                      6000         20
    SQL>
    SQL> INSERT INTO TEST1 (EMPNO)
      2  VALUES(SEQ.NEXTVAL);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> SELECT * fROM TEST1;
         EMPNO EMPTYPE              EMP_ADDRESS              SALARY     DEPTNO
             1 HR                   MUMBAI                    10000         10
             2 ADMIN                THANE                      6000         20
             1
    SQL>Now if you need to add different numbe in differenct condition then create multiple sequence and use them accounding.

Maybe you are looking for

  • Changing the default /Users location

    Hey guys, does anyone know a smart way to change the DEFAULT location of /Users in SL? I wan't to create a system image with /Users on a second partition, and i'm not talking about just ctrl-clicking an existing user and editing the account prefs Wor

  • Director 12 and iOS question

    We have a series of about 50-100 Director projects that our science teachers love, but due to intellectual property/ownership of code/providing technical support issues, we have no desire to publish these apps to the iOS App Store. Is it possible to

  • Stuck with ORA-02266...even through I've already disabled the FK constraints...?

    I'm working to help some people on a structure I really don't know much about...they're trying to truncate the table. When trying to truncate table1: I got the ORA-02266: unique/primary keys in table referenced by enabled foreign keys error, I went t

  • XSLT Sort Issues

    I have an XML document that give me a list of PO lines and orders. When I get the PIX message I want to sort it by PO number and then PO Line. For some reason my syntax below isn't working. I need to sort by Reference2 then Reference4. I tried to jus

  • SAP on Oracle RAC+ASM 11g - SWPM installation Option

    Dear Experts, I came across SAP Note 1977393 which is describing the installation steps of a RAC installation with SWPM with an example. However, the note is not describing the exact preparation steps to be performed on the cluster nodes. For example