Developer 6.0 doesn't like EXECUTE IMMEDIATE

I am trying to use the EXECUTE IMMEDIATE command in a WHEN-NEW-RECORD-INSTANCE trigger. However, no matter what I do, I get the following error when I try to compile the trigger:
Encountered the symbol "IMMEDIATE" when expecting one of the following:
:= . ( @ % ;
The symbol ":= was inserted before "IMMEDIATE" to continue.
My syntax looks good--I don't know what the problem is

EXECUTE IMMEDIATE , the native dynamic SQL is a feature available only from pl/sql version 8.1.5 . But forms6i is still using pl/sql engin 8.0.6. SO you can create stored procedures ( because Oracle 8i - pl/sql version -8.1.5) and call it in your forms.

Similar Messages

  • Disadvantage with 'Execute Immediate'

    What is the disadvantage with 'EXECUTE IMMEDIATE'.

    I think you guys are missing the point here.
    None of the issues listed are 'EXECUTE IMMEDIATE' disadvantages.
    'EXECUTE IMMEDIATE' is a tool. Like DMS_SQL. Like ref cursors. Like explicit cursor. Like implicit cursors.
    A tool, any tool, needs to be used correctly. If you use a hammer and hit a nail so hard that it bents, causing the hammer to slip doing some serious damage to your thumb... whose fault it is?
    Is it The Hammer that is at fault here? Or is the user of that tool?
    There are no disadvantages to using 'EXECUTE IMMEDIATE'. It is a tool. But like all tools it needs to be used correctly and safely. Things like excessive hard parsing because of a severe lack of bind variables, or opening a hole for SQL injection, etc.. all these are symptoms of - and let's be blunt here - an ignorant developer. It has nothing to do with the tool 'EXECUTE IMMEDIATE'.
    And those same type of errors will be made by Mr Ignorant Developer using other tools in Oracle.
    Shoddy workmanship is not because of poor tools. Shoddy code is not because of using a specific feature (like execute immediate).
    The proper question to ask is thus not "what are the disadvantages of execute immediate", but rather "where should I typically use execute immediate and how?".
    Not every developer will know how to use every single tool in the toolbox (I sure don't know all the tools in the Oracle toolbox). So there is nothing wrong with asking.
    But asking what is "wrong" with a tool (aka "what are the disadvantages") is in my view seriously missing the point that a tool is there to solve very specific types of problems...
    That is what a developer should be after - How to use the tool correctly.

  • Using 'execute immediate'

    Hi,
    for instance, we have 4 parameters for that, i remember we should use each parameter ONLY ONCE within the statement. am i right? Or we can reuse each parameter again and again?
    like
    execute immediate 'select ...
    where :4=''a''
    and :4<>'' '''
    Rgds,
    HuaMin

    Unfortunately I don't think so you can reuse the same parameter.
      1  declare
      2  v_sql varchar2(2000);
      3  v_no number;
      4  v_count number;
      5  begin
      6  v_no := 7369;
      7  v_sql := 'select count(*) from emp where empno = :1 and sal = :1';
      8  execute immediate v_sql into v_count using v_no ;
      9  dbms_output.put_line('Count is : ' || v_count);
    10* end;
    SQL> /
    declare
    ERROR at line 1:
    ORA-01008: not all variables bound
    ORA-06512: at line 8
      1  declare
      2  v_sql varchar2(2000);
      3  v_no number;
      4  v_count number;
      5  v_sal  number;
      6  begin
      7  v_no := 7369;
      8  v_sal := 800;
      9  v_sql := 'select count(*) from emp where empno = :1 and sal = :1';
    10  execute immediate v_sql into v_count using v_no, v_sal ;
    11  dbms_output.put_line('Count is : ' || v_count);
    12* end;
    SQL> set serveroutput on
    SQL> /
    Count is : 1
    PL/SQL procedure successfully completed.
    After swapping the variable names v_sal, v_no
      1  declare
      2  v_sql varchar2(2000);
      3  v_no number;
      4  v_count number;
      5  v_sal  number;
      6  begin
      7  v_no := 7369;
      8  v_sal := 800;
      9  v_sql := 'select count(*) from emp where empno = :1 and sal = :1';
    10  execute immediate v_sql into v_count using v_sal, v_no ;
    11  dbms_output.put_line('Count is : ' || v_count);
    12* end;
    SQL> /
    Count is : 0
    PL/SQL procedure successfully completed.Hope this helps
    Regards
    Raj

  • Unable to INSERT PL/SQL  record with EXECUTE IMMEDIATE

    Hi All,
    I am selecting data from a source table and after some modification inserting into a target table. Source and target table name are available at run time. You can say only source table structure is fixed.
    I have crated a pl/sql table of type source record and inserting record by record in target table using execute immediate. But I am not able to write
    EXECUTE IMMEDIATE string USING pl_sql_table(index); and getting error as
    PLS-00457: expressions have to be of SQL types
    Please see the part of code below. Is it possible to use FORALL with dynamic sql like
    FORALL pl_sql_table.FIRST .. pl_sql_table.COUNT
    EXECUTE IMMEDIATE .... pl_sql_table(j); -- Like this.
    Please suggest why I am not able to write record here. I also want to replace 'INSERT in a loop' with a single INSERT statement out of the loop, to upload whole pl_sql table into target table in one go.
    Thanks,
    Ravi
    DECLARE
        TYPE rec_tab_CMP IS RECORD
         model_id          NUMBER(38),   
         absolute_rank          NUMBER(5)         
        v_rec_tab_CMP  rec_tab_CMP;
        TYPE t_rec_tab_CMP IS TABLE OF v_rec_tab_CMP%TYPE INDEX BY BINARY_INTEGER;
        v_records_CMP               t_rec_tab_CMP;
        rc                          SYS_REFCURSOR;
        v_old_table_name            VARCHAR2(30); -- passed from parameter 
        v_new_table_name            VARCHAR2(30); -- passed from parameter 
        dyn_str                     VARCHAR2(500);
        v_columns_str               VARCHAR2(200) := ' model_id, absolute_rank ';
    BEGIN
           EXECUTE IMMEDIATE 'CREATE TABLE '|| v_new_table_name || ' AS SELECT * FROM ' || v_old_table_name ||' WHERE 1 = 2 ' ;
         OPEN rc FOR 'SELECT '|| v_columns_str ||' FROM '|| v_old_table_name;
         FETCH rc BULK COLLECT INTO v_records_CMP;
         FOR j IN 1..v_records_CMP.COUNT
         LOOP
            v_records_CMP(j).model_id := 1; -- Do someting here, This thing can be performed in SQL stmt directly.
            dyn_str := 'INSERT INTO '|| v_new_table_name ||' ( '|| v_columns_str || ' ) VALUES (:1, :2) ';
            EXECUTE IMMEDIATE dyn_str USING v_records_CMP(j).model_id          ,
                                v_records_CMP(j).absolute_rank     ;
         -- Here in place of two columns I want to use one record like
         -- EXECUTE IMMEDIATE dyn_str USING v_records_CMP(j);
         -- But it is giving me error like
            --          EXECUTE IMMEDIATE dyn_str USING v_records_st(j);
            --   PLS-00457: expressions have to be of SQL types
         END LOOP;
         CLOSE rc;
    END;
    /

    You cannot bind PL/SQL record types to dynamic SQL.
    Possibly you could work around this by declaring the INDEX-BY table of records at package specification level, e.g.
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> CREATE PACKAGE package_name
      2  AS
      3     TYPE tt_emp IS TABLE OF emp%ROWTYPE;
      4     t_emp tt_emp;
      5  END package_name;
      6  /
    Package created.
    SQL> CREATE TABLE new_emp
      2  AS
      3     SELECT *
      4     FROM   emp
      5     WHERE  1 = 0;
    Table created.
    SQL> DECLARE
      2     v_table_name user_tables.table_name%TYPE := 'NEW_EMP';
      3  BEGIN
      4     SELECT *
      5     BULK COLLECT INTO package_name.t_emp
      6     FROM   emp;
      7
      8     EXECUTE IMMEDIATE
      9        'BEGIN ' ||
    10        '   FORALL i IN 1 ..package_name.t_emp.COUNT ' ||
    11        '      INSERT INTO ' || v_table_name ||
    12        '      VALUES package_name.t_emp (i); ' ||
    13        'END;';
    14  END;
    15  /
    PL/SQL procedure successfully completed.
    SQL> SELECT empno, ename
      2  FROM   new_emp;
         EMPNO ENAME
          7369 SMITH
          7499 ALLEN
          7521 WARD
          7566 JONES
          7654 MARTIN
          7698 BLAKE
          7782 CLARK
          7788 SCOTT
          7839 KING
          7844 TURNER
          7876 ADAMS
          7900 JAMES
          7902 FORD
          7934 MILLER
    14 rows selected.
    SQL>

  • How to make my Execute Immediate statement to work??

    Hi, Sir:
    I use SQL Oracle 9i,
    I have following procedure called by a trigger:
    CREATE OR REPLACE PROCEDURE emps_check IS
    s_sql VARCHAR2(500);
    BEGIN
    DBMS_OUTPUT.PUT_LINE('1. Start to Delete all rows in the emps' );
    delete from emps;
    DBMS_OUTPUT.PUT_LINE('2. Start to insert into emps from emp' );
    s_sql:='INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO from emp;';
    DBMS_OUTPUT.PUT_LINE('3. s_sql= ' || s_sql );
    EXECUTE IMMEDIATE s_sql;
    DBMS_OUTPUT.PUT_LINE('3. Procedure call OK, Employ Name ' );
    EXCEPTION
    -- Use this to trap the ORA-00942: table or view does not exist
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Procedure call Exception: Employ Name ' );
    end emps_check;
    My trigger is:
    CREATE OR REPLACE TRIGGER emps_biu_after
    after INSERT OR UPDATE or delete on emp
    for each row
    begin
    if TO_CHAR(SYSDate,'DY')= 'SUN'
    then
    DBMS_OUTPUT.PUT_LINE('Today is holiday, ename =' );
    else
    DBMS_OUTPUT.PUT_LINE('Today is working Day, ename =');
    emps_check();
    end if;
    end;
    When I use following to update emp table:
    SQL> UPDATE emp T1
    2 SET T1.sal = 200.0
    3 WHERE T1.ename like '%SCOTT%';
    I got:
    Today is working Day, Trigger Call Procedure emps_check()
    1. Start to Delete all rows in the emps
    2. Start to insert into emps from emp
    3. s_sql= INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR
    Procedure call Exception: Employ Name
    Trigger Call Procedure emps_check() Success
    Looks like EXECUTE IMMEDIATE s_sql; did not work.
    What is wrong??
    How to make my Execute Immediate statement to work??
    Thanks

    You may omit the ';' character...
    s_sql:='INSERT INTO
    Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
    select EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO
    from emp';
    ... and something else
    IN PL/SQL when a procedure , function doews not take
    any parameter(s) then its call can be made as simply
    its name without a pair of parenthesis....(It seems
    that you are influenced by Java...:) )
    SimThanks Sir:
    I remove this ; but still error:
    1 UPDATE emp T1
    2 SET T1.sal = 768.1
    3* wHERE T1.ename like '%SCOTT%'
    SQL> /
    Today is working Day, Trigger Call Procedure emps_check()
    1. Start to Delete all rows in the emps
    2. Start to insert into emps from emp
    3. s_sql= INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR,
    Procedure call Exception: Employ Name
    Trigger Call Procedure emps_check() Success
    My code as follows:
    CREATE OR REPLACE PROCEDURE emps_check IS
    s_sql VARCHAR2(500);
    BEGIN
    DBMS_OUTPUT.PUT_LINE('1. Start to Delete all rows in the emps' );
    delete from emps;
    DBMS_OUTPUT.PUT_LINE('2. Start to insert into emps from emp' );
    s_sql:='INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO from emp';
    DBMS_OUTPUT.PUT_LINE('3. s_sql= ' || s_sql );
    EXECUTE IMMEDIATE s_sql;
    DBMS_OUTPUT.PUT_LINE('3. Procedure call OK, Employ Name ' );
    EXCEPTION
    -- Use this to trap the ORA-00942: table or view does not exist
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Procedure call Exception: Employ Name ' );
    end emps_check;
    what is other wrong??
    Yes, I am java guys,
    Thanks

  • EXECUTE IMMEDIATE with an update FUNCTION returning VARCHAR2

    I need to execute immediate a stored Function (that updates the database) and returns a VARCHAR2 value.
    What does my execute immediate statement look like:
    EXECUTE IMMEDIATE 'BEGIN my_function_call; END;' RETURNING INTO return_variable;

    A set of procedures would be far preferable to a set of functions if you're doing DML.
    Additionally, I'd get rid of the status value entirely and just raise an exception if there is an error. It's a heck of a lot easier to catch (or propagate) exceptions correctly than to ensure that each and every piece of code that calls these procedures checks the return code and acts appropriately. It's way too easy to miss/ hide an error in a missed return code.
    Justin

  • Execute immediate return

    Hi,
    I want to know if it's possible to use the return clause with the insert statement with EXECUTE IMMEDIATE.
    My code looks like:
    execute immediate('INSERT INTO '||p_nameDB||'.TableName (col1) VALUES (:1)
         ') using p_col1;
    The id is generated automatically with a trigger (and a sequence). And I want to recuperate it in a variable after the insert statement. I don't want to do a seq.currval after because i'm afraid that there will be a mix match with the sequence and the id if 2 persons accede at the same time.
    thanks

    execute immediate 'insert into trial (a) values (:1) returning a into :2' using a1 returning into x ;

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

  • 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

  • How can i pass multiple values by a single variable to EXECUTE IMMEDIATE

    Hi All,
    I want to pass multiple values for where condition for execute immediate. Something Like this:-
    bold
    Declare
    v_cond varchar(1000);
    Begin
    v_cond := '''INR','USD'''; --(OPTION 1)
    v_cond := 'INR,USD'; --(OPTION 2)
    EXECUTE IMMEDIATE 'Delete from table where colm in (:v_cond)' using v_cond;
    END;
    bold
    I am using this into a procedure
    Now option 1 gives an error ie a syntax error (; expected or something like that)(I am sorry, i can't tell the exact error here as i am not in the office right now)
    and option 2 makes the procedure execute but obviously doesn't delete the records, as it takes the whole as one.
    Please Help
    Regards
    Neeraj Bansal

    See the links containing examples under
    *7. List of values in an IN clause?*
    SQL and PL/SQL FAQ
    from the SQL and PL/SQL FAQ.

  • How to set multiple parameters in one EXECUTE IMMEDIATE sql

    I want to set both nls_language and nls_date_language, and set them as different languages. fnd_global.set_nls_context() doesn't work. So I think maybe I can use the EXECUTE IMMEDIATE, and add them together into one statement. But I don't know how to make that happen. Can anybody help me? Thanks very much.
    PS: It has to be done in one call.

    928091 wrote:
    Hey, thanks for your answer, I forgot to mention that it has to be in begin-end block, do you know how?EXEC is a SQL Plus API that can be used to run PL/SQL code. What it does is put the PL/SQL code in a BEGIN .. END block and run it.
    So you can also manually put the code in a BEGIN..END block and run like this.
    SQL> begin
      2     execute immediate q'[begin execute immediate 'alter session set nls_date_language = ''AMERICAN'''; execute immediate 'alter session set nls_language = ''AMERICAN'''; end;]';
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> And i dont understand what possible benefit does it makes to do a single execution into a BEGIN..END over multiple execution.
    Why this code is not of your interest, something like this
    begin
         execute immediate 'alter session set nls_date_language = ''AMERICAN''';
         execute immediate 'alter session set nls_language = ''AMERICAN''';
    end;
    /

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

  • Error while using execute immediate

    Hi,
    I am trying to get the record count of a table. The table name is saved in a variable..
    when i am writing the code like below its working fine.
    SELECT count(*) into count1 FROM emp1;
    DBMS_OUTPUT.PUT_LINE(count1);
    but when i am using the code for the table name in variable its giving error
    execute immediate 'SELECT count(*) into count1 FROM ' || t_name;
    DBMS_OUTPUT.PUT_LINE(count1);
    the error is
    ERROR at line 1:
    ORA-00905: missing keyword
    ORA-06512: at "SYSTEM.TEST_COL", line 14
    ORA-06512: at line 1
    any help
    Ashish

    Interesting, the into count doesn't be a problem, but the count variable usage does :
    SQL> set serveroutput on
    SQL> l
      1  declare
      2     count number;
      3     t_name varchar2(30):='all_objects';
      4  begin
      5     execute immediate 'select count(*) from ' || t_name into count;
      6  exception when others then dbms_output.put_line(sqlcode||' : '||sqlerrm);
      7* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL> declare
      2     count number;
      3     t_name varchar2(30):='all_objects';
      4  begin
      5     execute immediate 'select count(*) from ' || t_name into count;
      6     dbms_output.put_line(count);
      7  exception when others then dbms_output.put_line(sqlcode||' : '||sqlerrm);
      8* end;
    SQL> /
       dbms_output.put_line(count);
    ERROR at line 6:
    ORA-06550: line 6, column 25:
    PLS-00204: function or pseudo-column 'COUNT' may be used inside a SQL statement
    only
    ORA-06550: line 6, column 4:
    PL/SQL: Statement ignoredNicolas.

  • ORA-01006 in execute immediate

    Hi Everyone!
    Please help!
    What's wrong with this code?
    create or replace procedure rgo_test_forall
    as
      v_actie                        varchar2( 200 ) := 'BEGIN';
      cursor c_sjv
      is
        select   1 netb_totaal
               , 'prf' profiel
               , 'naam' netbeheerder
            from dual;
      type tt_sjv is table of c_sjv%rowtype
        index by binary_integer;
      t_sjv_netb                         tt_sjv;
      l_idx_netb                     pls_integer;
      cursor c_sjv_ean(
        b_profiel                   in       varchar2
      , b_netbeheerder              in       varchar2
      , b_netb_totaal               in       number )
      is
        select 1  ean_totaal
             , 1 / b_netb_totaal fractie
             , 'loc' locatie
             , 'prf' profiel
             , 'ptf' portfolio
             , b_netbeheerder netbeheerder
        from   dual;
      type tt_sjv_ean is table of c_sjv_ean%rowtype
        index by binary_integer;
      t_sjv_ean                         tt_sjv_ean;
      l_idx_ean                     pls_integer;
      type tt_fractie is table of number
             index by binary_integer;
      type tt_netbeheerder is table of varchar2( 400 )
             index by binary_integer;
      type tt_profiel is table of varchar2( 400 )
             index by binary_integer;
      t_fractie                        tt_fractie;
      t_netbeheerder                   tt_netbeheerder;
      t_profiel                        tt_profiel;
      v_maand                       date := to_date( '200711', 'yyyymm' );
      v_aantal_toegevoegd           pls_integer := 0;
      v_fractie                     number;
      procedure splits_tabel(
                   origtable_in     in     tt_sjv_ean
                 , fractie_tab_out     out tt_fractie
                 , netb_tab_out        out tt_netbeheerder
                 , profiel_tab_out     out tt_profiel )
       is
         l_idx    pls_integer := origtable_in.first;
       begin
         while l_idx is not null
         loop
            fractie_tab_out( l_idx ) := origtable_in( l_idx ).fractie;
            netb_tab_out( l_idx ) := origtable_in( l_idx ).netbeheerder;
            profiel_tab_out( l_idx ) := origtable_in( l_idx ).profiel;
            l_idx := origtable_in.next( l_idx );
         end loop;
       end splits_tabel;
    begin
      open c_sjv;
      loop
        v_actie := 'bulk collect';
        fetch c_sjv
        bulk collect into t_sjv_netb limit 1000;
                               -- only 200 rows are expected
        exit when t_sjv_netb.count = 0;
        l_idx_netb := t_sjv_netb.first;
        while l_idx_netb is not null
        loop
          open c_sjv_ean(
                  t_sjv_netb( l_idx_netb ).profiel
                , t_sjv_netb( l_idx_netb ).netbeheerder
                , t_sjv_netb( l_idx_netb ).netb_totaal );
          loop
            v_actie := 'bulk collect EAN';
            fetch c_sjv_ean
            bulk collect into t_sjv_ean limit 10000;
            exit when t_sjv_ean.count = 0;
            v_actie := 'splits tabel';
              splits_tabel(
                   origtable_in     => t_sjv_ean
                 , fractie_tab_out  => t_fractie
                 , netb_tab_out     => t_netbeheerder
                 , profiel_tab_out  => t_profiel );
            v_actie := 'forall insert';
            forall i in t_sjv_ean.first .. t_sjv_ean.last
              execute immediate
              'insert into rgot( ptf, volume_plat ) values( ' ||
              '                  substr( '':netbeheerder'' || '' '' || '':profiel'', 1, 30 ) ' ||
              '                , '':fractie'' )'
               using t_netbeheerder( i ), t_profiel( i ), t_fractie( i );
          end loop;
          l_idx_netb := t_sjv_netb.next( l_idx_netb );
        end loop;
      end loop;
    exception
    when others
    then
       dbms_output.put_line( 'OTHERS: ' || sqlcode || ': ' || substr( sqlerrm, 1, 100 ) );
    end rgo_test_forall;
    sho errI get ORA-01006 when I run it. I have tried replacing the execute immediate statement with the code below, but that way I cannot compile the code.
            forall i in t_sjv_ean.first .. t_sjv_ean.last
              execute immediate
              'insert into rgot( ptf, volume_plat ) values( ' ||
              '                  substr( '''||:netbeheerder||''' || '' '' || '''||:profiel||''', 1, 30 ) ' ||
              '                , '''||:fractie||''' )'
               using t_netbeheerder( i ), t_profiel( i ), t_fractie( i );Next, I tried with the code below, but then no row was inserted.
            forall i in t_sjv_ean.first .. t_sjv_ean.last
              execute immediate
              'insert into rgot( ptf, volume_plat ) values( ' ||
              '                  substr( ''''||:netbeheerder||'''' || '' '' || ''''||:profiel||'''', 1, 30 ) ' ||
              '                , ''''||:fractie||'''' )'
               using t_netbeheerder( i ), t_profiel( i ), t_fractie( i );Any ideas?
    By the way: the cursor definitions have been simplified for readability, of course.
    Message was edited by:
    RemcoGoris

    I am sorry, I am but a simple silly little developer who doesn't have good ideas.
    Since you are someone who has good ideas, I would consider myself a very very happy man if you were to tell me what the result of the 'debugging' should be.
    This?
    INSERT INTO rgot(
           ptf
         , volume_plat )
    VALUES(
          substr( :netbeheerder || ' ' || :profiel, 1, 30 )
        , :fractie );Humble thanks!

  • 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

Maybe you are looking for