How to improve performance using bulk collects with plsql tables or arrays

Hi All,
my procedure is like this
declare
cursor c1 is select ----------------------
begin
assigning to variables
validations on that variables
--50 validations are here --
insert into a table
end;
we have created indexes on primary keys,
i want to use
DECLARE
CURSOR a_cur IS
SELECT program_id
FROM airplanes;
TYPE myarray IS TABLE OF a_cur%ROWTYPE;
cur_array myarray;
BEGIN
OPEN a_cur;
LOOP
FETCH a_cur BULK COLLECT INTO cur_array LIMIT 100;
***---------can i assign cursor data to the plsql table variables or array***
***validate on the pl sql variable as---***
i
nsert into a table
EXIT WHEN a_cur%NOTFOUND;
END LOOP;
CLOSE a_cur;
END;
Edited by: Veekay on Oct 21, 2011 4:28 AM

Fastest way often is this:
insert /*+append */
into aTable
select * from airplanes;
commit;The select and insert part can even be done in parallel if needed.
However if the oparation is complex or the dataset is very very very very very large or the programmer is decent but not excellent then the bulk approach should be considered. It is often a pretty stable and linear scaling approach.
The solution depends a little on the database version.
LOOP
  FETCH a_cur BULK COLLECT INTO cur_array LIMIT 100;
  EXIT WHEN a_cur.count = 0;
  forall i in a_cur.first.. a_cur.last
  insert into aTable (id)
  values (a_cur(i));
END LOOP;
...If you have more then one column then you might need a single collection for each column. Other possibilities depend on the db version.
Also: do not exit using a_cur%NOTFOUND. This is wrong! You might loose records from the end of the data set.

Similar Messages

  • Error using BULK Collect with RECORD TYPE

    hello
    I have written a simple Procedure by declaring a record type & then making a variable of NESTED Table type.
    I then select data using BULK COLLECT & tryin to access it through a LOOP.....Getting an ERROR.
    CREATE OR REPLACE PROCEDURE sp_test_bulkcollect
    IS
    TYPE rec_type IS RECORD (
    emp_id VARCHAR2(20),
    level_id NUMBER
    TYPE v_rec_type IS TABLE OF rec_type;
    BEGIN
    SELECT employee_id, level_id
    BULK COLLECT INTO v_rec_type
    FROM portfolio_exec_level_mapping
    WHERE portfolio_execp_id = 2851852;
    FOR indx IN v_rec_type.FIRST..v_rec_type.LAST
    LOOP
    dbms_output.put_line('Emp -- '||v_rec_type.emp_id(indx)||' '||v_rec_type.level_id(indx));
    END LOOP;
    END;
    Below are the ERROR's i am getting ....
    - Compilation errors for PROCEDURE DOMRATBDTESTUSER.SP_TEST_BULKCOLLECT
    Error: PLS-00321: expression 'V_REC_TYPE' is inappropriate as the left hand side of an assignment statement
    Line: 15
    Text: FROM portfolio_exec_level_mapping
    Error: PL/SQL: ORA-00904: : invalid identifier
    Line: 16
    Text: WHERE portfolio_execp_id = 2851852;
    Error: PL/SQL: SQL Statement ignored
    Line: 14
    Text: BULK COLLECT INTO v_rec_type
    Error: PLS-00302: component 'FIRST' must be declared
    Line: 19
    Text: LOOP
    Error: PL/SQL: Statement ignored
    Line: 19
    Text: LOOP
    PLZ Help.

    and with a full code sample:
    SQL> CREATE OR REPLACE PROCEDURE sp_test_bulkcollect
      2  IS
      3  TYPE rec_type IS RECORD (
      4  emp_id VARCHAR2(20),
      5  level_id NUMBER
      6  );
      7  TYPE v_rec_type IS TABLE OF rec_type;
      8  v v_rec_type;
      9  BEGIN
    10     SELECT empno, sal
    11     BULK COLLECT INTO v
    12     FROM emp
    13     WHERE empno = 7876;
    14     FOR indx IN v.FIRST..v.LAST
    15     LOOP
    16        dbms_output.put_line('Emp -- '||v(indx).emp_id||' '||v(indx).level_id);
    17     END LOOP;
    18  END;
    19  /
    Procedure created.
    SQL>
    SQL> show error
    No errors.
    SQL>
    SQL> begin
      2     sp_test_bulkcollect;
      3  end;
      4  /
    Emp -- 7876 1100
    PL/SQL procedure successfully completed.

  • How to handle the bad record while using bulk collect with limit.

    Hi
    How to handle the Bad record as part of the insertion/updation to avoid the transaction.
    Example:
    I am inserting into table with LIMIT of 1000 records and i've got error at 588th record.
    i want to commit the transaction with 588 inserted record in table and log the error into
    error logging table then i've to continue with transaction with 560th record.
    Can anyone suggest me in this case.
    Regards,
    yuva

    >
    How to handle the Bad record as part of the insertion/updation to avoid the transaction.
    >
    Use the SAVE EXCEPTIONS clause of the FORALL if you are doing bulk inserts.
    See SAVE EXCEPTIONS in the PL/SQL Language doc
    http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/tuning.htm
    And then see Example 12-9 Bulk Operation that continues despite exceptions
    >
    Example 12-9 Bulk Operation that Continues Despite Exceptions
    -- Temporary table for this example:
    CREATE TABLE emp_temp AS SELECT * FROM employees;
    DECLARE
    TYPE empid_tab IS TABLE OF employees.employee_id%TYPE;
    emp_sr empid_tab;
    -- Exception handler for ORA-24381:
    errors NUMBER;
    dml_errors EXCEPTION;
    PRAGMA EXCEPTION_INIT(dml_errors, -24381);
    BEGIN
    SELECT employee_id
    BULK COLLECT INTO emp_sr FROM emp_temp
    WHERE hire_date < '30-DEC-94';
    -- Add '_SR' to job_id of most senior employees:
    FORALL i IN emp_sr.FIRST..emp_sr.LAST SAVE EXCEPTIONS
    UPDATE emp_temp SET job_id = job_id || '_SR'
    WHERE emp_sr(i) = emp_temp.employee_id;
    -- If errors occurred during FORALL SAVE EXCEPTIONS,
    -- a single exception is raised when the statement completes.
    EXCEPTION
    -- Figure out what failed and why
    WHEN dml_errors THEN
    errors := SQL%BULK_EXCEPTIONS.COUNT;
    DBMS_OUTPUT.PUT_LINE
    ('Number of statements that failed: ' || errors);
    FOR i IN 1..errors LOOP
    DBMS_OUTPUT.PUT_LINE('Error #' || i || ' occurred during '||
    'iteration #' || SQL%BULK_EXCEPTIONS(i).ERROR_INDEX);
    DBMS_OUTPUT.PUT_LINE('Error message is ' ||
    SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
    END LOOP;
    END;
    DROP TABLE emp_temp;

  • Using bulk collect with select

    i am working on oracle 10g release 2 .
    My requirement is like this
      1  declare
      2     type id_type is table of fnd_menus.menu_id%type;
      3     id_t id_type;
      4     cursor cur_menu is select menu_name from menu;
      5     type name_type is table of menu.menu_name%type;
      6     name_t name_type;
      7  begin
      8     open cur_menu;
      9     fetch cur_menu bulk collect into name_t;
    10     forall i in name_t.first..name_t.last
    11             select menu_id into id_t(i) from fnd_menus where menu_name = name_t(i);
    12* end;
    SQL> /
                    select menu_id into id_t(i) from fnd_menus where menu_name = name_t(i);
    ERROR at line 11:
    ORA-06550: line 11, column 23:
    PLS-00437: FORALL bulk index cannot be used in INTO clause
    ORA-06550: line 11, column 31:
    PL/SQL: ORA-00904: : invalid identifier
    ORA-06550: line 11, column 3:
    PL/SQL: SQL Statement ignoredSo how i can bulk select into a table the rows that satisfy a particular condition ?

    A forall statement is used bulk execute DML, as can be read [url http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/forall_statement.htm#LNPLS01321]here in the documentation.
    I guess you want something like this:
    SQL> create table menu
      2  as
      3  select 'A' menu_name from dual union all
      4  select 'B' from dual union all
      5  select 'C' from dual
      6  /
    Tabel is aangemaakt.
    SQL> create table fnd_menus
      2  as
      3  select 10 menu_id, 'A' menu_name from dual union all
      4  select 9, 'B' from dual union all
      5  select 8, 'C' from dual union all
      6  select 7, 'D' from dual
      7  /
    Tabel is aangemaakt.
    SQL> declare
      2    type id_type is table of fnd_menus.menu_id%type;
      3    id_t id_type;
      4    cursor cur_menu is select menu_name from menu;
      5    type name_type is table of menu.menu_name%type;
      6    name_t name_type;
      7  begin
      8    open cur_menu;
      9    fetch cur_menu bulk collect into name_t;
    10    forall i in name_t.first..name_t.last
    11      select menu_id into id_t(i) from fnd_menus where menu_name = name_t(i);
    12  end;
    13  /
        select menu_id into id_t(i) from fnd_menus where menu_name = name_t(i);
    FOUT in regel 11:
    .ORA-06550: Regel 11, kolom 25:
    PLS-00437: FORALL-bulkindex kan niet worden gebruikt in INTO-clausule..
    ORA-06550: Regel 11, kolom 33:
    PL/SQL: ORA-00904: : ongeldige ID.
    ORA-06550: Regel 11, kolom 5:
    PL/SQL: SQL Statement ignored.
    SQL> declare
      2    type id_type is table of fnd_menus.menu_id%type;
      3    id_t id_type;
      4  begin
      5    select menu_id
      6      bulk collect into id_t
      7      from fnd_menus
      8     where menu_name in (select menu_name from menu)
      9    ;
    10    for i in 1..id_t.count
    11    loop
    12      dbms_output.put_line(id_t(i));
    13    end loop
    14    ;
    15  end;
    16  /
    10
    9
    8
    PL/SQL-procedure is geslaagd.Regards,
    Rob.

  • How to improve performance(insert,delete and search) of table with large data.

    Hi,
    I am having a table which is used for maintaining history and have a large data and that keeps on increasing or decreasing based on the business rules.
    I am getting performance issues with this table which searching for any records or while inserting new data into it. I have already used index in this table but still I am facing lot of issues related to performance.
    Also, we used to insert bulk data into this table.
    Can we have any solution to achieve this, any solutions are greatly appreciated.
    Thanks in Advance!

    Please do not duplicate your posts across forums.  It's considered bad practice and rude, as people will not know what answers you've already received and may end up duplicating the effort.
    Locking this thread - answer on other thread please

  • How to improve performance on SD document with over 1000 line items

    Dear experts,
    A lot of our SD document contains 1500 to 5000 line items. Saving a simple change of one line item description would take 5 minutes (with or without pricing considerations). We are on ECC 5.0. Does anyone know of an existing snote or ways that would help to improve performance?
    A related question on performance tracing. I have done some tracing and notice that the time to access SQL/buffer/enqueue/RFC only amount to less than 50% (sometimes 5%) of the total processing time. What has the system been doing for the "unrecorded" time?
    Thank you and appreciate!
    -cynthia

    I would check which modules or which parts of code take the most of the processing time. You can use SE30 to check one order save.
    If it's not SQL - then it may be internal processing like inefficient loops and so on.  For example runtime of nested loops with big tables have grows exponentially.
    It may be caused by SAP code - search OSS notes for based on the module names which consume most time.
    OR it can be caused by the code in your userexits - then developers have to fix it and redesign using more efficient technique.

  • How to improve performance for bulk data load in Dynamics CRM 2013 Online

    Hi all,
    We need to bulk update (or create) contacts into Dynamics CRM 2013 online every night due to data updated from another external data source.  The data size is around 100,000 and the data loading duration was around 6 hours.
    We are already using ExecuteMultiple web services to handle the integration, however, the 6 hours integraton duration is still not acceptable and we are seeking for any advise for further improvement. 
    Any help is highly appreciated.  Many thanks.
    Gary

    I think Andrii's referring to running multiple threads in parallel (see
    http://www.mscrmuk.blogspot.co.uk/2012/02/data-migration-performance-to-crm.html - it's a bit dated, but should still be relevant).
    Microsoft do have some throttling limits applied in Crm Online, and it is worth contacting them to see if you can get those raised.
    100 000 records per night seems a large number. Are all these records new or updated records, or are there some that are unchanged, in which case you could filter them out before uploading ? Or are there useful ways to summarise the data before loading
    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

  • How to improve performance using SDO_RDF_MATCH

    Hello,
    I have a virtual model that I created from an entailment containing about 10 models. It has approx 7.5 million triples. And running a simple query as follows could take about 30-35 sec:
    select x, o, y, o1, z, o2, f
    from table(sdo_rdf_match(
    '{ ?x ?o ?y .
    ?y ?o1 ?z
    optional {?z ?o2 ?f}}',
    sdo_rdf_models('vm_m'),
    null,
    null,
    null,
    null));
    I have 11.2.0.3 database running on a Sun Solaris server.
    I've analyzed the entailmend and run refresh_sem_network_index_info.
    Is there a way to speed this query?
    Thanks,
    A.

    Hi,
    The query was not something specific but just an example to illustrate that queries that have several paths can run very slowly.
    I'm using with the Jena query QueryOptions.ALLOW_QUERY_INVALID_AND_DUP
    How would I check the query plan and whether hash join is adopted?
    Also I'm running it in parallel, I'll give this one a try.
    Thanks,
    A.

  • How to use BULK COLLECT in oracle forms

    hi gurus,
    I am using oracle forms
    Forms [32 Bit] Version 10.1.2.0.2 (Production)
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionI wanna use bulk collect from database table lets say <employees>
    while working on database level with collections and records it's working very well for me, but when I try to use that technique on oracle forms it hits me error
    error 591 this feature is not supported in client side programmingI know I can use cursors to loop through the records of oracle tables ,
    but I'm convenient while using collections and arrays
    for example
    Set Serveroutput On
    Declare
          Type Rec_T Is Record (     
           Empid Number ,
           Empname Varchar2(100)
          Type V_R Is Table Of Rec_T Index By Binary_Integer;     
          V_Array V_R;
    Begin
       Select Employee_Id , First_Name
       Bulk Collect
       Into V_Array
          From Employees; 
       For Indx In V_Array.First..V_Array.Last Loop
       Dbms_Output.Put_Line('employees id '||V_Array(Indx).Empid ||'and the name is '||V_Array(Indx).Empname);
       End Loop;      
         End;I wanna use this same way on oracle forms , for certain purposes , please guide me how can I use ...
    thanks...

    For information, you can use and populate a collection within the Forms application without using the BULK COLLECT
    Francoisactually I want to work with arrays , index tables ,
    like
             record_type (variable , variable2);
             type type_name <record_type>  index by binary_integer
            type_variable type_name;
            and in main body of program
            select something
            bulk collect into type_variable
            from any_table;
           loop
                type_variable(indx).variable , type_variable(indx).variable2;
           end loop;
           this is very useful for my logic on which I am working
              like
              type_variable(indx).variable || type_variable(indx-1);
             if it's possible with cursors then how can I use cursor that can fullfill my this logic@Francois
    if it's possible then how can i populate without using bulk collect?
    thanks
    and for others replies: if I can use stored procedures please give me any example..
    thanks

  • Can I use Bulk Collect results as input parameter for another cursor

    MUSIC            ==> remote MUSIC_DB database, MUSIC table has 60 million rows
    PRICE_DATA ==> remote PRICING_DB database, PRICE_DATE table has 1 billion rows
    These two table once existed in same database, but size of database exceeded available hardware size and hardware budget, so the PRICE_DATA table was moved to another Oracle database.  I need to create a single report that combines data from both of these tables, and a distributed join with DRIVING_SITE hint will not work because the size of both table is too large to push to one DRIVING_SITE location, so I wrote this PLSQL block to process in small blocks.
    QUESTION: how can use bulk collect from one cursor and pass that bulk collected information as input to second cursor without specifically listing each cell of the PLSQL bulk collection?  See sample pseudo-code below, I am trying to determine more efficient way to code than hard-coding 100 parameter names into 2nd cursor.
    NOTE: below is truly pseudo-code, I had to change the names of everything to adhere to NDA, but below works and is fast enough for my purposes, but if I want to change from 100 input parameters to 200, I have to add more hard-coded values.  There has got to be a better way.
    DECLARE
         -- define cursor that retrieves distinct SONG_IDs from MUSIC table in remote music database
         CURSOR C_CURRENT_MUSIC
         IS
        select distinct SONG_ID
        from MUSIC@MUSIC_DB
        where PRODUCTION_RELEASE=1
         /*  define a parameterized cursor that accepts 100 SONG_IDs and retrieves
              required pricing information
         CURSOR C_get_music_price_data
                   P_SONG_ID_001 NUMBER, P_SONG_ID_002 NUMBER, P_SONG_ID_003 NUMBER, P_SONG_ID_004 NUMBER, P_SONG_ID_005 NUMBER, P_SONG_ID_006 NUMBER, P_SONG_ID_007 NUMBER, P_SONG_ID_008 NUMBER, P_SONG_ID_009 NUMBER, P_SONG_ID_010 NUMBER,
                   P_SONG_ID_011 NUMBER, P_SONG_ID_012 NUMBER, P_SONG_ID_013 NUMBER, P_SONG_ID_014 NUMBER, P_SONG_ID_015 NUMBER, P_SONG_ID_016 NUMBER, P_SONG_ID_017 NUMBER, P_SONG_ID_018 NUMBER, P_SONG_ID_019 NUMBER, P_SONG_ID_020 NUMBER,
                   P_SONG_ID_021 NUMBER, P_SONG_ID_022 NUMBER, P_SONG_ID_023 NUMBER, P_SONG_ID_024 NUMBER, P_SONG_ID_025 NUMBER, P_SONG_ID_026 NUMBER, P_SONG_ID_027 NUMBER, P_SONG_ID_028 NUMBER, P_SONG_ID_029 NUMBER, P_SONG_ID_030 NUMBER,
                   P_SONG_ID_031 NUMBER, P_SONG_ID_032 NUMBER, P_SONG_ID_033 NUMBER, P_SONG_ID_034 NUMBER, P_SONG_ID_035 NUMBER, P_SONG_ID_036 NUMBER, P_SONG_ID_037 NUMBER, P_SONG_ID_038 NUMBER, P_SONG_ID_039 NUMBER, P_SONG_ID_040 NUMBER,
                   P_SONG_ID_041 NUMBER, P_SONG_ID_042 NUMBER, P_SONG_ID_043 NUMBER, P_SONG_ID_044 NUMBER, P_SONG_ID_045 NUMBER, P_SONG_ID_046 NUMBER, P_SONG_ID_047 NUMBER, P_SONG_ID_048 NUMBER, P_SONG_ID_049 NUMBER, P_SONG_ID_050 NUMBER,
                   P_SONG_ID_051 NUMBER, P_SONG_ID_052 NUMBER, P_SONG_ID_053 NUMBER, P_SONG_ID_054 NUMBER, P_SONG_ID_055 NUMBER, P_SONG_ID_056 NUMBER, P_SONG_ID_057 NUMBER, P_SONG_ID_058 NUMBER, P_SONG_ID_059 NUMBER, P_SONG_ID_060 NUMBER,
                   P_SONG_ID_061 NUMBER, P_SONG_ID_062 NUMBER, P_SONG_ID_063 NUMBER, P_SONG_ID_064 NUMBER, P_SONG_ID_065 NUMBER, P_SONG_ID_066 NUMBER, P_SONG_ID_067 NUMBER, P_SONG_ID_068 NUMBER, P_SONG_ID_069 NUMBER, P_SONG_ID_070 NUMBER,
                   P_SONG_ID_071 NUMBER, P_SONG_ID_072 NUMBER, P_SONG_ID_073 NUMBER, P_SONG_ID_074 NUMBER, P_SONG_ID_075 NUMBER, P_SONG_ID_076 NUMBER, P_SONG_ID_077 NUMBER, P_SONG_ID_078 NUMBER, P_SONG_ID_079 NUMBER, P_SONG_ID_080 NUMBER,
                   P_SONG_ID_081 NUMBER, P_SONG_ID_082 NUMBER, P_SONG_ID_083 NUMBER, P_SONG_ID_084 NUMBER, P_SONG_ID_085 NUMBER, P_SONG_ID_086 NUMBER, P_SONG_ID_087 NUMBER, P_SONG_ID_088 NUMBER, P_SONG_ID_089 NUMBER, P_SONG_ID_090 NUMBER,
                   P_SONG_ID_091 NUMBER, P_SONG_ID_092 NUMBER, P_SONG_ID_093 NUMBER, P_SONG_ID_094 NUMBER, P_SONG_ID_095 NUMBER, P_SONG_ID_096 NUMBER, P_SONG_ID_097 NUMBER, P_SONG_ID_098 NUMBER, P_SONG_ID_099 NUMBER, P_SONG_ID_100 NUMBER
         IS
         select
         from PRICE_DATA@PRICING_DB
         where COUNTRY = 'USA'
         and START_DATE <= sysdate
         and END_DATE > sysdate
         and vpc.SONG_ID IN
                   P_SONG_ID_001 ,P_SONG_ID_002 ,P_SONG_ID_003 ,P_SONG_ID_004 ,P_SONG_ID_005 ,P_SONG_ID_006 ,P_SONG_ID_007 ,P_SONG_ID_008 ,P_SONG_ID_009 ,P_SONG_ID_010,
                   P_SONG_ID_011 ,P_SONG_ID_012 ,P_SONG_ID_013 ,P_SONG_ID_014 ,P_SONG_ID_015 ,P_SONG_ID_016 ,P_SONG_ID_017 ,P_SONG_ID_018 ,P_SONG_ID_019 ,P_SONG_ID_020,
                   P_SONG_ID_021 ,P_SONG_ID_022 ,P_SONG_ID_023 ,P_SONG_ID_024 ,P_SONG_ID_025 ,P_SONG_ID_026 ,P_SONG_ID_027 ,P_SONG_ID_028 ,P_SONG_ID_029 ,P_SONG_ID_030,
                   P_SONG_ID_031 ,P_SONG_ID_032 ,P_SONG_ID_033 ,P_SONG_ID_034 ,P_SONG_ID_035 ,P_SONG_ID_036 ,P_SONG_ID_037 ,P_SONG_ID_038 ,P_SONG_ID_039 ,P_SONG_ID_040,
                   P_SONG_ID_041 ,P_SONG_ID_042 ,P_SONG_ID_043 ,P_SONG_ID_044 ,P_SONG_ID_045 ,P_SONG_ID_046 ,P_SONG_ID_047 ,P_SONG_ID_048 ,P_SONG_ID_049 ,P_SONG_ID_050,
                   P_SONG_ID_051 ,P_SONG_ID_052 ,P_SONG_ID_053 ,P_SONG_ID_054 ,P_SONG_ID_055 ,P_SONG_ID_056 ,P_SONG_ID_057 ,P_SONG_ID_058 ,P_SONG_ID_059 ,P_SONG_ID_060,
                   P_SONG_ID_061 ,P_SONG_ID_062 ,P_SONG_ID_063 ,P_SONG_ID_064 ,P_SONG_ID_065 ,P_SONG_ID_066 ,P_SONG_ID_067 ,P_SONG_ID_068 ,P_SONG_ID_069 ,P_SONG_ID_070,
                   P_SONG_ID_071 ,P_SONG_ID_072 ,P_SONG_ID_073 ,P_SONG_ID_074 ,P_SONG_ID_075 ,P_SONG_ID_076 ,P_SONG_ID_077 ,P_SONG_ID_078 ,P_SONG_ID_079 ,P_SONG_ID_080,
                   P_SONG_ID_081 ,P_SONG_ID_082 ,P_SONG_ID_083 ,P_SONG_ID_084 ,P_SONG_ID_085 ,P_SONG_ID_086 ,P_SONG_ID_087 ,P_SONG_ID_088 ,P_SONG_ID_089 ,P_SONG_ID_090,
                   P_SONG_ID_091 ,P_SONG_ID_092 ,P_SONG_ID_093 ,P_SONG_ID_094 ,P_SONG_ID_095 ,P_SONG_ID_096 ,P_SONG_ID_097 ,P_SONG_ID_098 ,P_SONG_ID_099 ,P_SONG_ID_100
         group by
               vpc.SONG_ID
              ,vpc.STOREFRONT_ID
         TYPE SONG_ID_TYPE IS TABLE OF MUSIC@MUSIC_DB%TYPE INDEX BY BINARY_INTEGER;
         V_SONG_ID_ARRAY                         SONG_ID_TYPE                     ;
         v_commit_counter           NUMBER := 0;
    BEGIN
         /* open cursor you intent to bulk collect from */
         OPEN C_CURRENT_MUSIC;
         LOOP
              /* in batches of 100, bulk collect ADAM_ID mapped TMS_IDENTIFIER into PLSQL table or records */
              FETCH C_CURRENT_MUSIC BULK COLLECT INTO V_SONG_ID_ARRAY LIMIT 100;
                   EXIT WHEN V_SONG_ID_ARRAY.COUNT = 0;
                   /* to avoid NO DATA FOUND error when pass 100 parameters to OPEN cursor, if the arrary
                      is not fully populated to 100, pad the array with nulls to fill up to 100 cells. */
                   IF (V_SONG_ID_ARRAY.COUNT >=1 and V_SONG_ID_ARRAY.COUNT <> 100) THEN
                        FOR j IN V_SONG_ID_ARRAY.COUNT+1..100 LOOP
                             V_SONG_ID_ARRAY(j) := null;
                        END LOOP;
                   END IF;
              /* pass a batch of 100 to cursor that get price information per SONG_ID and STOREFRONT_ID */
              FOR j IN C_get_music_price_data
                        V_SONG_ID_ARRAY(1) ,V_SONG_ID_ARRAY(2) ,V_SONG_ID_ARRAY(3) ,V_SONG_ID_ARRAY(4) ,V_SONG_ID_ARRAY(5) ,V_SONG_ID_ARRAY(6) ,V_SONG_ID_ARRAY(7) ,V_SONG_ID_ARRAY(8) ,V_SONG_ID_ARRAY(9) ,V_SONG_ID_ARRAY(10) ,
                        V_SONG_ID_ARRAY(11) ,V_SONG_ID_ARRAY(12) ,V_SONG_ID_ARRAY(13) ,V_SONG_ID_ARRAY(14) ,V_SONG_ID_ARRAY(15) ,V_SONG_ID_ARRAY(16) ,V_SONG_ID_ARRAY(17) ,V_SONG_ID_ARRAY(18) ,V_SONG_ID_ARRAY(19) ,V_SONG_ID_ARRAY(20) ,
                        V_SONG_ID_ARRAY(21) ,V_SONG_ID_ARRAY(22) ,V_SONG_ID_ARRAY(23) ,V_SONG_ID_ARRAY(24) ,V_SONG_ID_ARRAY(25) ,V_SONG_ID_ARRAY(26) ,V_SONG_ID_ARRAY(27) ,V_SONG_ID_ARRAY(28) ,V_SONG_ID_ARRAY(29) ,V_SONG_ID_ARRAY(30) ,
                        V_SONG_ID_ARRAY(31) ,V_SONG_ID_ARRAY(32) ,V_SONG_ID_ARRAY(33) ,V_SONG_ID_ARRAY(34) ,V_SONG_ID_ARRAY(35) ,V_SONG_ID_ARRAY(36) ,V_SONG_ID_ARRAY(37) ,V_SONG_ID_ARRAY(38) ,V_SONG_ID_ARRAY(39) ,V_SONG_ID_ARRAY(40) ,
                        V_SONG_ID_ARRAY(41) ,V_SONG_ID_ARRAY(42) ,V_SONG_ID_ARRAY(43) ,V_SONG_ID_ARRAY(44) ,V_SONG_ID_ARRAY(45) ,V_SONG_ID_ARRAY(46) ,V_SONG_ID_ARRAY(47) ,V_SONG_ID_ARRAY(48) ,V_SONG_ID_ARRAY(49) ,V_SONG_ID_ARRAY(50) ,
                        V_SONG_ID_ARRAY(51) ,V_SONG_ID_ARRAY(52) ,V_SONG_ID_ARRAY(53) ,V_SONG_ID_ARRAY(54) ,V_SONG_ID_ARRAY(55) ,V_SONG_ID_ARRAY(56) ,V_SONG_ID_ARRAY(57) ,V_SONG_ID_ARRAY(58) ,V_SONG_ID_ARRAY(59) ,V_SONG_ID_ARRAY(60) ,
                        V_SONG_ID_ARRAY(61) ,V_SONG_ID_ARRAY(62) ,V_SONG_ID_ARRAY(63) ,V_SONG_ID_ARRAY(64) ,V_SONG_ID_ARRAY(65) ,V_SONG_ID_ARRAY(66) ,V_SONG_ID_ARRAY(67) ,V_SONG_ID_ARRAY(68) ,V_SONG_ID_ARRAY(69) ,V_SONG_ID_ARRAY(70) ,
                        V_SONG_ID_ARRAY(71) ,V_SONG_ID_ARRAY(72) ,V_SONG_ID_ARRAY(73) ,V_SONG_ID_ARRAY(74) ,V_SONG_ID_ARRAY(75) ,V_SONG_ID_ARRAY(76) ,V_SONG_ID_ARRAY(77) ,V_SONG_ID_ARRAY(78) ,V_SONG_ID_ARRAY(79) ,V_SONG_ID_ARRAY(80) ,
                        V_SONG_ID_ARRAY(81) ,V_SONG_ID_ARRAY(82) ,V_SONG_ID_ARRAY(83) ,V_SONG_ID_ARRAY(84) ,V_SONG_ID_ARRAY(85) ,V_SONG_ID_ARRAY(86) ,V_SONG_ID_ARRAY(87) ,V_SONG_ID_ARRAY(88) ,V_SONG_ID_ARRAY(89) ,V_SONG_ID_ARRAY(90) ,
                        V_SONG_ID_ARRAY(91) ,V_SONG_ID_ARRAY(92) ,V_SONG_ID_ARRAY(93) ,V_SONG_ID_ARRAY(94) ,V_SONG_ID_ARRAY(95) ,V_SONG_ID_ARRAY(96) ,V_SONG_ID_ARRAY(97) ,V_SONG_ID_ARRAY(98) ,V_SONG_ID_ARRAY(99) ,V_SONG_ID_ARRAY(100)        
              LOOP
                   /* do stuff with data from Song and Pricing Database coming from the two
                        separate cursors, then continue processing more rows...
              END LOOP;
              /* commit after each batch of 100 SONG_IDs is processed */        
              COMMIT;
              EXIT WHEN C_CURRENT_MUSIC%NOTFOUND;  -- exit when there are no more rows to fetch from cursor
         END LOOP; -- bulk fetching loop
         CLOSE C_CURRENT_MUSIC; -- close cursor that was used in bulk collection
         /* commit rows */
         COMMIT; -- commit any remaining uncommitted data.
    END;

    I've got a problem when using passing VARRAY of numbers as parameter to remote cursor: it takes a super long time to run, sometimes doesn't finish even after an hour as passed.
    Continuing with my example in original entry, I replaced the bulk collect into PLSQL table collection with a VARRAY and i bulk collect into the VARRAY, this is fast and I know it works because I can DBMS_OUTPUT.PUT_LINE cells of VARRAY so I know it is getting populated correctly.  However, when I pass the VARRAY containing 100 cells populated with SONG_IDs as parameter to cursor, execution time is over an hour and when I am expecting a few seconds.
    Below code example strips the problem down to it's raw details, I skip the bulk collect and just manually populate a VARRAY with 100 SONG_ID values, then try to pass to as parameter to a cursor, but the execution time of cursor is unexpectedly long, over 30 minutes, sometime longer, when I am expecting seconds.
    IMPORTANT: If I take the same 100 SONG_IDs and place them directly in the cursor query's where IN clause, the SQL runs in under 5 seconds and returns result.  Also, if I pass the 100 SONG_IDs as individual cells of a PLSQL table collection, then it also runs fast.
    I thought that since the VARRAY is used via select subquery that is it queried locally, but the cursor is remote, and that I had a distribute problem on my hands, so I put in the DRIVING_SITE hint to attempt to force the result of query against VARRAY to go to remote server and rest of query will run there before returning result, but that didn't work either, still got slow response.
    Is something wrong with my code, or I am running into a Oracle problem that may require support to resolve?
    DECLARE
         /*  define a parameterized cursor that accepts XXX number of in SONG_IDs and
          retrieves required pricing information
         CURSOR C_get_music_price_data
      p_array_song_ids SYS.ODCInumberList              
         IS
         select  /*+DRIVING_SITE(pd) */
      count(distinct s.EVE_ID)
         from PRICE_DATA@PRICING_DB pd
         where pd.COUNTRY = 'USA'
         and pd.START_DATE <= sysdate
         and pd.END_DATE > sysdate
         and pd.SONG_ID IN
              select column_value from table(p_array_song_ids)
         group by
               pd.SONG_ID
              ,pd.STOREFRONT_ID
      V_ARRAY_SONG_IDS SYS.ODCInumberList := SYS.ODCInumberList();    
    BEGIN
    V_ARRAY_SONG_IDS.EXTEND(100);
    V_ARRAY_SONG_IDS(  1 ) := 31135  ;
    V_ARRAY_SONG_IDS(  2 ) := 31140   ;
    V_ARRAY_SONG_IDS(  3 ) := 31142   ;
    V_ARRAY_SONG_IDS(  4 ) := 31144   ;
    V_ARRAY_SONG_IDS(  5 ) := 31146   ;
    V_ARRAY_SONG_IDS(  6 ) := 31148   ;
    V_ARRAY_SONG_IDS(  7 ) := 31150   ;
    V_ARRAY_SONG_IDS(  8 ) := 31152   ;
    V_ARRAY_SONG_IDS(  9 ) := 31154   ;
    V_ARRAY_SONG_IDS( 10 ) := 31156   ;
    V_ARRAY_SONG_IDS( 11 ) := 31158   ;
    V_ARRAY_SONG_IDS( 12 ) := 31160   ;
    V_ARRAY_SONG_IDS( 13 ) := 33598   ;
    V_ARRAY_SONG_IDS( 14 ) := 33603   ;
    V_ARRAY_SONG_IDS( 15 ) := 33605   ;
    V_ARRAY_SONG_IDS( 16 ) := 33607   ;
    V_ARRAY_SONG_IDS( 17 ) := 33609   ;
    V_ARRAY_SONG_IDS( 18 ) := 33611   ;
    V_ARRAY_SONG_IDS( 19 ) := 33613   ;
    V_ARRAY_SONG_IDS( 20 ) := 33615   ;
    V_ARRAY_SONG_IDS( 21 ) := 33617   ;
    V_ARRAY_SONG_IDS( 22 ) := 33630   ;
    V_ARRAY_SONG_IDS( 23 ) := 33632   ;
    V_ARRAY_SONG_IDS( 24 ) := 33636   ;
    V_ARRAY_SONG_IDS( 25 ) := 33638   ;
    V_ARRAY_SONG_IDS( 26 ) := 33640   ;
    V_ARRAY_SONG_IDS( 27 ) := 33642   ;
    V_ARRAY_SONG_IDS( 28 ) := 33644   ;
    V_ARRAY_SONG_IDS( 29 ) := 33646   ;
    V_ARRAY_SONG_IDS( 30 ) := 33648   ;
    V_ARRAY_SONG_IDS( 31 ) := 33662   ;
    V_ARRAY_SONG_IDS( 32 ) := 33667   ;
    V_ARRAY_SONG_IDS( 33 ) := 33669   ;
    V_ARRAY_SONG_IDS( 34 ) := 33671   ;
    V_ARRAY_SONG_IDS( 35 ) := 33673   ;
    V_ARRAY_SONG_IDS( 36 ) := 33675   ;
    V_ARRAY_SONG_IDS( 37 ) := 33677   ;
    V_ARRAY_SONG_IDS( 38 ) := 33679   ;
    V_ARRAY_SONG_IDS( 39 ) := 33681   ;
    V_ARRAY_SONG_IDS( 40 ) := 33683   ;
    V_ARRAY_SONG_IDS( 41 ) := 33685   ;
    V_ARRAY_SONG_IDS( 42 ) := 33700   ;
    V_ARRAY_SONG_IDS( 43 ) := 33702   ;
    V_ARRAY_SONG_IDS( 44 ) := 33704   ;
    V_ARRAY_SONG_IDS( 45 ) := 33706   ;
    V_ARRAY_SONG_IDS( 46 ) := 33708   ;
    V_ARRAY_SONG_IDS( 47 ) := 33710   ;
    V_ARRAY_SONG_IDS( 48 ) := 33712   ;
    V_ARRAY_SONG_IDS( 49 ) := 33723   ;
    V_ARRAY_SONG_IDS( 50 ) := 33725   ;
    V_ARRAY_SONG_IDS( 51 ) := 33727   ;
    V_ARRAY_SONG_IDS( 52 ) := 33729   ;
    V_ARRAY_SONG_IDS( 53 ) := 33731   ;
    V_ARRAY_SONG_IDS( 54 ) := 33733   ;
    V_ARRAY_SONG_IDS( 55 ) := 33735   ;
    V_ARRAY_SONG_IDS( 56 ) := 33737   ;
    V_ARRAY_SONG_IDS( 57 ) := 33749   ;
    V_ARRAY_SONG_IDS( 58 ) := 33751   ;
    V_ARRAY_SONG_IDS( 59 ) := 33753   ;
    V_ARRAY_SONG_IDS( 60 ) := 33755   ;
    V_ARRAY_SONG_IDS( 61 ) := 33757   ;
    V_ARRAY_SONG_IDS( 62 ) := 33759   ;
    V_ARRAY_SONG_IDS( 63 ) := 33761   ;
    V_ARRAY_SONG_IDS( 64 ) := 33763   ;
    V_ARRAY_SONG_IDS( 65 ) := 33775   ;
    V_ARRAY_SONG_IDS( 66 ) := 33777   ;
    V_ARRAY_SONG_IDS( 67 ) := 33779   ;
    V_ARRAY_SONG_IDS( 68 ) := 33781   ;
    V_ARRAY_SONG_IDS( 69 ) := 33783   ;
    V_ARRAY_SONG_IDS( 70 ) := 33785   ;
    V_ARRAY_SONG_IDS( 71 ) := 33787   ;
    V_ARRAY_SONG_IDS( 72 ) := 33789   ;
    V_ARRAY_SONG_IDS( 73 ) := 33791   ;
    V_ARRAY_SONG_IDS( 74 ) := 33793   ;
    V_ARRAY_SONG_IDS( 75 ) := 33807   ;
    V_ARRAY_SONG_IDS( 76 ) := 33809   ;
    V_ARRAY_SONG_IDS( 77 ) := 33811   ;
    V_ARRAY_SONG_IDS( 78 ) := 33813   ;
    V_ARRAY_SONG_IDS( 79 ) := 33815   ;
    V_ARRAY_SONG_IDS( 80 ) := 33817   ;
    V_ARRAY_SONG_IDS( 81 ) := 33819   ;
    V_ARRAY_SONG_IDS( 82 ) := 33821   ;
    V_ARRAY_SONG_IDS( 83 ) := 33823   ;
    V_ARRAY_SONG_IDS( 84 ) := 33825   ;
    V_ARRAY_SONG_IDS( 85 ) := 33839   ;
    V_ARRAY_SONG_IDS( 86 ) := 33844   ;
    V_ARRAY_SONG_IDS( 87 ) := 33846   ;
    V_ARRAY_SONG_IDS( 88 ) := 33848   ;
    V_ARRAY_SONG_IDS( 89 ) := 33850   ;
    V_ARRAY_SONG_IDS( 90 ) := 33852   ;
    V_ARRAY_SONG_IDS( 91 ) := 33854   ;
    V_ARRAY_SONG_IDS( 92 ) := 33856   ;
    V_ARRAY_SONG_IDS( 93 ) := 33858   ;
    V_ARRAY_SONG_IDS( 94 ) := 33860   ;
    V_ARRAY_SONG_IDS( 95 ) := 33874   ;
    V_ARRAY_SONG_IDS( 96 ) := 33879   ;
    V_ARRAY_SONG_IDS( 97 ) := 33881   ;
    V_ARRAY_SONG_IDS( 98 ) := 33883   ;
    V_ARRAY_SONG_IDS( 99 ) := 33885   ;
    V_ARRAY_SONG_IDS(100 ) := 33889  ;
        /* do stuff with data from Song and Pricing Database coming from the two
      separate cursors, then continue processing more rows...
      FOR i IN C_get_music_price_data( v_array_song_ids ) LOOP
      . (this is the loop where I pass in v_array_song_ids
      .  populated with only 100 cells and it runs forever)
      END LOOP; 
    END;

  • Calling Stored procedure which uses Bulk Collect

    Hi All, I have Oracle stored procedure which uses Bulk Collect and returns table type parameter as output. Can anyone please help me how Can I call this kind of stored procedures which returns table type output using VB and Oracle's Driver. (I am successfully able to call using MS ODBC driver, but I want to use OraOLEDB driver.)

    861412 wrote:
    how Can I call this kind of stored procedures which returns table type output using VB and Oracle's Driver. This forum deals with the server-side languages SQL and PL/SQL.
    Your question deals with the client side and Visual Basic language.

  • Approach of using Bulk Collect

    Hi Experts,
    how to use bulk collect for uncertain number of columns of select statement.
    Master table structure:
    Create table tabmst
    (id number,
    cls_input varchar2(2000),
    price number);
    insert into tabmst(1,'select product, price from product',500);
    insert into tabmst(2,'select product, price,purchase_dt from product',100);
    insert into tabmst(3,'select * from product',1000);
    Currently I want to store Select statement of cls_input column in a local variable like
    dyn_qry:= cls_input; by using a cursor.
    Now my question is how to use Bulk Collect by using "Execute Immediate" in Bulk collect variable as there is not certainity of the number of columns from "Select Statment". Please suggest.
    Sample code:
    I created TYPE variable for Bulk Collect also support blk_var;
    Declare
    dyn_qry varchar2(3000);
    cursor c1 is select * from tabmst;
    begin
    for i in c1 loop
    dyn_qry:= cls_input;
    Execute immediate dyn_qry into blk_var;
    End Loop;
    End;
    Now I want to store values of Each "Select statements columns" which is executing by dynamic SQL. but it is uncertain that how many columns with return from dynamic SQL.
    Please suggest the approach on the same. Thanks in advance.

    >
    I don't think you can use bulk collect with EXECUTE IMMEDIATE. They do two different things. EXECUTE IMMEDIATE allows the execlution of dynamic SQL. BULK COLLECT provides optimization of SELECT statements when loading the contents into collections. I am not aware of any support for BULK COLLECT with EXECUTE IMMEDIATE.
    You may be able to do this a different way. If you must use dynamic SQL (I suggest you don't unless it is absolutely necessary. Dynamic SQL is hard to write, hard to debug, hard to maintain, and hard to tune) use a reference cursor instead. You can use the BULK COLLECT with the standard fetch.

  • Bulk collect with Nested loops

    Hi I've a requirement like this
    I need to pull request nos from table a(Master table)
    For every request no I need to pull request details from table b(Detail Table)
    For every request no I need to pull contact details from table c
    For every request no I need to pull customer data table d and I need to create a flat file with that data so I'm using utl_file in normal query criterion because of nested loops it's taking lot of time so I want to use bulk collect with dynamic query option:
    Sample code
    =======
    create or replace procedure test(region varchar2) as
    type tablea_request_typ is table of varchar2(10);
    tablea_data tablea_request_typ;
    type tableb_request_typ is table of varchar2(1000);
    tableb_data tableb_request_typ;
    type tablec_request_typ is table of varchar2(1000);
    tablec_data tablec_request_typ;
    type tabled_request_typ is table of varchar2(1000);
    tabled_data tabled_request_typ;
    stmta varchar2(32000);
    stmtb varchar2(32000);
    stmtc varchar2(32000);
    stmtd varchar2(32000);
    rcura SYS_REFCURSOR;
    rcurb SYS_REFCURSOR;
    rcurc SYS_REFCURSOR;
    rcurd SYS_REFCURSOR;
    begin
    stmta:='select  request_no from tablea where :region'||'='NE';
    stmtb:='select  request_no||request_detail1||request_detail2 stringb  from table b where :region'||'='NE';
    stmtc:='select contact1||contact2||contact3||contact4  stringc from table c where :region'||'='NE';
    stmtd:='select customer1||customer2||customer3||customer4  stringd  from table c where :region'||'='NE';
    OPEN rcura for stmta;
      LOOP
      FETCH rcura BULK COLLECT INTO request_no
      LIMIT 1000;
      FOR  f in 1..request_no.count
    LOOP
    --Tableb
        OPEN rcurb for stmtb USING substr(request_no(f),1,14);
      LOOP
      FETCH rcurb BULK COLLECT INTO tableb_data
    for i in 1..tableb_data.count
    LOOP
    utl_file(...,tableb_data(i));
    END LOOP;
        EXIT WHEN rcurb%NOTFOUND;
      END LOOP;
    -- Tablec
    OPEN rcurc for stmtc USING substr(request_no(f),1,14);
      LOOP
      FETCH rcurb BULK COLLECT INTO tablec_data
    for i in 1..tablec_data.count
    LOOP
    utl_file(...,tablec_data(i));
    END LOOP;
        EXIT WHEN rcurc%NOTFOUND;
      END LOOP;
    -- Tabled
    OPEN rcurd for stmtd USING substr(request_no(f),1,14);
      LOOP
      FETCH rcurd BULK COLLECT INTO tabled_data
    for i in 1..tabled_data.count
    LOOP
    utl_file(...,tabled_data(i));
    END LOOP;
        EXIT WHEN rcurd%NOTFOUND;
      END LOOP;
      END LOOP;
        EXIT WHEN rcura%NOTFOUND;
      END LOOP;
    exception
    when other then
    dbms_output.put_line(sqlerrm);
    end;I 'm using code mentioned above but request nos are repeating as if it's an infinete loop ?for ex if request no is 222 It should run once but here it's running more than once?
    How to pass bind parameters say in my case region?
    Are there any alternate solutions to run it faster apart from using bulk collect?
    Right now I'm using explicit cursor with for loop which is taking lot of time ?so is this better sol?
    Thanks,
    Mahender
    Edited by: BluShadow on 24-Aug-2011 08:52
    added {noformat}{noformat} tags. Please read {message:id=9360002} to learn to format your code/data yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

        Use Parameterized cursor :
    CREATE OR REPLACE PROCEDURE test(region varchar2)
    AS
      type tablea_request_typ is table of varchar2(10);
      type tableb_request_typ is table of varchar2(1000); 
      type tablec_request_typ is table of varchar2(1000);
      type tabled_request_typ is table of varchar2(1000);
      tablea_data tablea_request_typ;
      tableb_data tableb_request_typ;
      tablec_data tablec_request_typ;
      tabled_data tabled_request_typ;
       CURSOR rcura(v_region  VARCHAR2(100))
       IS
       select  request_no from tablea where region = v_region;
       CURSOR rcurb(v_input  VARCHAR2(100))
       IS
       select  request_no||request_detail1||request_detail2 stringb  from table b where request_num = v_input;
       CURSOR rcurc(v_input  VARCHAR2(100))
       IS
       select  select contact1||contact2||contact3||contact4  stringc from table c where request_num = v_input;
       CURSOR rcurd(v_input  VARCHAR2(100))
       IS
       select  select customer1||customer2||customer3||customer4  stringd  from table c where request_num = v_input;
    BEGIN
    OPEN rcura('NE');
    LOOP
        FETCH rcura BULK COLLECT INTO request_no  LIMIT 1000;
        FOR  f in 1..request_no.count
        LOOP
           --Tableb
           OPEN rcurb(substr(request_no(f),1,14));
           LOOP
              FETCH rcurb BULK COLLECT INTO tableb_data
              for i in 1..tableb_data.count
              LOOP
                  utl_file(...,tableb_data(i));
              END LOOP;
              EXIT WHEN rcurb%NOTFOUND;
           END LOOP;
           -- Tablec
           OPEN rcurc (substr(request_no(f),1,14));
           LOOP
              FETCH rcurb BULK COLLECT INTO tablec_data
              for i in 1..tablec_data.count
              LOOP
                 utl_file(...,tablec_data(i));
              END LOOP;
              EXIT WHEN rcurc%NOTFOUND;
           END LOOP;
           -- Tabled
           OPEN rcurd ( substr(request_no(f),1,14) );
           LOOP
              FETCH rcurd BULK COLLECT INTO tabled_data
              for i in 1..tabled_data.count
              LOOP
               utl_file(...,tabled_data(i));
              END LOOP;
              EXIT WHEN rcurd%NOTFOUND;
           END LOOP;
      END LOOP;
    EXIT WHEN rcura%NOTFOUND;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
       dbms_output.put_line(dbms_utility.format_error_backtrace);
    END;
    /Hope this helps. If not, post your table structures...

  • ORA-06502 during a procedure which uses Bulk collect feature and nested tab

    Hello Friends,
    have created one procedure which uses Bulk collect and nested table to hold the bulk data. This procedure was using one cursor and a nested table with the same type as the cursor to hold data fetched from cursor. Bulk collection technique was used to collect data from cursor to nested table. But it is giving ORA-06502 error.
    I reduced code of procedure to following to trace the error point. But still error is comming. Please help us to find the cause and solve it.
    Script which is giving error:
    declare
    v_Errorflag BINARY_INTEGER;
    v_flag number := 1;
    CURSOR cur_terminal_info Is
    SELECT distinct
    'a' SettlementType
    FROM
    dual;
    TYPE typ_cur_terminal IS TABLE OF cur_terminal_info%ROWTYPE;
    Tab_Terminal_info typ_cur_Terminal;
    BEGIN
    v_Errorflag := 2;
    OPEN cur_terminal_info;
    LOOP
    v_Errorflag := 4;
    FETCH cur_terminal_info BULK COLLECT INTO tab_terminal_info LIMIT 300;
    EXIT WHEN cur_terminal_info%rowcount &lt;= 0;
    v_Errorflag := 5;
    FOR Y IN Tab_Terminal_Info.FIRST..tab_terminal_info.LAST
    LOOP
    dbms_output.put_line(v_flag);
    v_flag := v_flag + 1;
    end loop;
    END LOOP;
    v_Errorflag := 13;
    COMMIT;
    END;
    I have updated script as following to change datatype as varchar2 for nested table, but still same error is
    comming..
    declare
    v_Errorflag BINARY_INTEGER;
    v_flag number := 1;
    CURSOR cur_terminal_info Is
    SELECT distinct
    'a' SettlementType
    FROM
    dual;
    TYPE typ_cur_terminal IS TABLE OF varchar2(50);
    Tab_Terminal_info typ_cur_Terminal;
    BEGIN
    v_Errorflag := 2;
    OPEN cur_terminal_info;
    LOOP
    v_Errorflag := 4;
    FETCH cur_terminal_info BULK COLLECT INTO tab_terminal_info LIMIT 300;
    EXIT WHEN cur_terminal_info%rowcount &lt;= 0;
    v_Errorflag := 5;
    FOR Y IN Tab_Terminal_Info.FIRST..tab_terminal_info.LAST
    LOOP
    dbms_output.put_line(v_flag);
    v_flag := v_flag + 1;
    end loop;
    END LOOP;
    v_Errorflag := 13;
    COMMIT;
    I could not find the exact reason of error.
    Please help us to solve this error.
    Thanks and Regards..
    Dipali..

    Hello Friends,
    I got the solution.. :)
    I did one mistake in procedure where the loop should end.
    I used the statemetn: EXIT WHEN cur_terminal_info%rowcount &lt;= 0;
    But it should be: EXIT WHEN Tab_Terminal_Info.COUNT &lt;= 0;
    Now my script is working fine.. :)
    Thanks and Regards,
    Dipali..

  • How to use BULK COLLECT in Oracle Forms 11g

    Forms is showing error that "Feature is not support in Client Side Program" when i am trying to impliment Bulk collect in Forms 11g.
    i need to load full data from DB to my form becuase using cursor is very slow....
    Is there any method/Work around to achieve this ....

    declare
    type arr is table of emp%rowtype ;
    lv_arr arr;
    begin
    select * bulk collect in to lv_arr from emp;
    /*written code here to process the data and write in to file*/
    end;Unless you are inserting/updating the data you are holding in the array into a database table I don't think there is much peformance gain in using bulk-collect in conjunction with writing a file. Bulk processing will increase performance by minimizing context switches from the SQL to the PL/SQL engine, nothing more, nothing less.
    In any case bulk processing is not available in forms, if you really need to make use of it you need to do it in a stored procedure.
    cheers

Maybe you are looking for

  • Issues while iterating BDB XML

    Hello there, to begin with the issue, I've got a BDB XML, with couple of inserted documents. Using Java API. I'm creating an application which integrates the database within and displays the contents (that is, documents) of a container in a JTree. Ne

  • Php-cgi php not same version still works?

    Maybe this post should have gone in the Package issues forum, but I thought more people would know about that kind of thing in this forum. Anyways, I noticed that php-cgi was at version 5.2.1 and php main package is at 5.2.2. If i'm using lighttpd do

  • CR2010 Report Viewer control crashes application when deployed

    I have been using the latest release for CR2010, on a Win 7 x64 machine running VS2010 targeting .Net Framework V4, and all is working fine. However, when I publish my WPF application as an x86 client and deploy to a WinXP machine, the Report Viewer

  • Use the system lang of AIR applications auto update.

    Hello, I recently used the auto update framework for my AIR application, this works fine but i have a small problem. I made some reasearches and i found AIR uses the system lang by default. When i install my package for the first time, the lang is my

  • ADF ViewCriteria - Nested Query issue.

    Hi, JDev 11.1.1..2.0. I have the following tables. TableMaster ---- TableDetail1 ---- TableDetail2 -----------TableDetail2.1 ------------TableDetails2,2 I have created the required viewLinks and On TableMaster I have created a ViewCriteria where I ha