Bulk collect into compound array

Hi guys,
just having a bit of an issue here. here's what I've got so far (simplified):
declare
type t_rec is record(foo_rec foo%rowtype,
                             id number);
type t_tab is table of t_rec index by pls_integer;
w_footab t_tab;
begin
select foo.*,
         3
bulk collect into w_footab
  from foo;
end;but I get the error pls00597 expression w_footab in the INTO list is of wrong type.
oracle version: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi

Hi WhiteHat,
You can't select into a layered PL/SQL structure like this.
SQL> create table foo (col1,col2) as select 1,2 from dual
  2  /
Tabel is aangemaakt.
SQL> declare
  2    type t_rec is record
  3    ( foo_rec foo%rowtype
  4    , id number
  5    );
  6    type t_tab is table of t_rec index by pls_integer;
  7    w_footab t_tab;
  8  begin
  9    select foo.*
10         , 3
11           bulk collect into w_footab
12      from foo
13    ;
14  end;
15  /
         bulk collect into w_footab
FOUT in regel 11:
.ORA-06550: line 11, column 28:
PLS-00597: expression 'W_FOOTAB' in the INTO list is of wrong type
ORA-06550: line 12, column 5:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 9, column 3:
PL/SQL: SQL Statement ignoredWhen you flatten it out, it works:
SQL> declare
  2    type t_rec is record
  3    ( col1 foo.col1%type
  4    , col2 foo.col2%type
  5    , id number
  6    );
  7    type t_tab is table of t_rec index by pls_integer;
  8    w_footab t_tab;
  9  begin
10    select foo.*
11         , 3
12           bulk collect into w_footab
13      from foo
14    ;
15  end;
16  /
PL/SQL-procedure is geslaagd.Or use SQL types, and you can use any structure you want:
SQL> create type foorec is object
  2  ( foo_col1 number
  3  , foo_col2 number
  4  );
  5  /
Type is aangemaakt.
SQL> declare
  2    type t_rec is record
  3    ( foo_rec foorec
  4    , id number
  5    );
  6    type t_tab is table of t_rec index by pls_integer;
  7    w_footab t_tab;
  8  begin
  9    select foorec(foo.col1,foo.col2)
10         , 3
11           bulk collect into w_footab
12      from foo
13    ;
14  end;
15  /
PL/SQL-procedure is geslaagd.Regards,
Rob.

Similar Messages

  • Multiple Bulk Collects into same array

    If I do a Bulk Collect into the same array, will it replace the data already in the array, or will it append it in the array?

    Here is the block of code where I am performing my checks...
    The first check just looks up a student by their id. The second one looks up their student by a combination of name and address. The third one looks up a student by name and email. If you get through all three checks and still have duplicates, I need to process all the duplicates I found in all three checks.
      /*****FIRST_CHECK******/
      EXECUTE IMMEDIATE '
        SELECT student_id
        FROM eapp.students
        WHERE interface_id = '''||suppression_data(v_count).id_number||''' '
      BULK COLLECT INTO duplicates_student_id ;
      IF duplicates_student_id.COUNT = 1 THEN
        update_records(v_count) ;
      ELSE
        /*****SECOND_CHECK******/
        EXECUTE IMMEDIATE '
          SELECT student_id
          FROM eapp.students
          WHERE TRIM(first_name)||'' ''||TRIM(last_name)||'' ''||SUBSTR(address1,1,10)||'' ''||SUBSTR(zip,1,5) = '||TRIM(suppression_data(v_count).first_name)||' '||TRIM(suppression_data(v_count).last_name)||' '||SUBSTR(suppression_data(v_count).address1,1,10)||' '||SUBSTR(suppression_data(v_count).zip,1,5)||''
        BULK COLLECT INTO duplicates_student_id ;
        IF duplicates_student_id.COUNT = 1 THEN
          update_records(v_count) ;
        ELSE
          /*****THIRD_CHECK******/
          EXECUTE IMMEDIATE '
            SELECT student_id
            FROM eapp.students
            WHERE TRIM(first_name)||'' ''||TRIM(last_name)||'' ''||TRIM(email) = '||TRIM(suppression_data(v_count).first_name)||' '||TRIM(suppression_data(v_count).last_name)||' '||TRIM(suppression_data(v_count).email)||''
          BULK COLLECT INTO duplicates_student_id ;
          IF duplicates_student_id.COUNT = 1 THEN
            update_records(v_count) ;
          ELSE
            --process all records found here and set eapp.students.duplicate = 1
            FOR i IN 1..duplicates_student_id.COUNT LOOP
              update_records(i) ;
            END LOOP ;
          END IF ;
        END IF ;
      END IF ;

  • Bulk collect into associative array

    Please advise examples of a bulkk collecting a cursor into associative array amd working on the basis of one column as key.
    Here need to calculate based onnfollowing data and key as Col1 until all records for that key are worked upon.
    Col1 col2 col3 Flag
    AA A11 A13 1
    AA A12 A13 1
    BB B11 B11 1
    BB B11 B11 2
    CC C11 C11 1

    ?:|
    You might want to rephrase your question...
    http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
    Examples:
    http://www.java2s.com/Code/Oracle/PL-SQL/Howtodoabulkcollectintoanassociativearray.htm
    http://www.oracle-developer.net/display.php?id=201
    http://www.oracle.com/pls/db102/search?word=bulk+collect
    http://www.oracle.com/pls/db102/search?word=associative+array

  • Oracle sql query - bulk collect into a 50 element array,  to print them.

    INSERT INTO temp_mobile_donors_au
    select distinct d.donor_id
    from [email protected] d,
    blood_drives b,
    ds_malaria_travel_history h
    where b.site_code = 'NA19'
    and d.coll_date between trunc(add_months(sysdate,-24))
    and trunc(sysdate)
    and d.drive_id = 'DRV'||b.drive_id
    and h.donor_id = d.donor_id;
    I have 105 donors. I am taking these donors and have to print a report. I was using loop to print the donor sheet for each donor. Usually we have about 20 to 30 donors. So reports prints without any problem. Now we have about 105 donors and may be next time we may have more. So report does not print for all donors.
    I print reports using this command
    Cursor C2 is
    select distinct donor_id
    from temp_mobile_donors_au;
    Begin
    Open C2;
    Loop
    Fetch C2 into :param_donor_id;
    Exit when C2%notfound;
    print_mobile_donor_sheets_au;
    End loop;
    Close C2;
    End;
    procedure for print_mobile_donor_sheet_au----- is as below
    v_url_c := 'http://'||v_rep_server_c||'report=r_ds_travel_history1&param_donor_id='||:control.param_donor_id;
    Is there a way to iterate through a single cursor 50 rows at a time, bulk collect into a 50 element array, print them, bulk collect the next batch.
    Any idea or help?

    Here is a bulk-collect-limit example that got by googling:
    SET SERVEROUTPUT ON
    DECLARE
      TYPE t_bulk_collect_test_tab IS TABLE OF bulk_collect_test%ROWTYPE;
      l_tab    t_bulk_collect_test_tab;
      CURSOR c_data IS
        SELECT *
        FROM   bulk_collect_test;
    BEGIN
      OPEN c_data;
      LOOP
        FETCH c_data
        BULK COLLECT INTO l_tab LIMIT 10000; /*I think this is what you are looking for*/
        -- Process contents of collection here.
        DBMS_OUTPUT.put_line(l_tab.count || ‘ rows’);
        EXIT WHEN c_data%NOTFOUND;
      END LOOP
      CLOSE c_data;
    END;
    /So you need to three things:
    1.  TYPE t_bulk_collect_test_tab IS TABLE OF bulk_collect_test%ROWTYPE;
    2.  l_tab    t_bulk_collect_test_tab;
    3. FETCH c_data
             BULK COLLECT INTO l_tab LIMIT 10000; /* use your reqd value */Change your code and try.
    HTH

  • Please help with an embedded query (INSERT RETURNING BULK COLLECT INTO)

    I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
    Here is a full query that use in the C# code
    string sql = "INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, " +
    "SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, " +
    "BENEFICIARY_FIRST_NAME, BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, " +
    "CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE, LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, " +
    "UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL, ATTENDING_PROVIDER_NUMBER, " +
    "BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI) " +
    "VALUES " +
    "(SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs, :REQUEST_METHOD_IDs, " +
    ":SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs, :SERVICE_LOCATION_STATEs, " +
    ":BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs, :HICNUMs, :CCNs, " +
    ":CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs, :CONTRACTOR_IDs, :PRIORITY_IDs, " +
    ":UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs, :ATTENDING_PROVIDER_NUMBERs, " +
    ":BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs, :STUDY_IDs, :REFERRING_NPIs) " +
    " RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs";
    int[] REQUEST_IDs = new int[range];
    cmd.Parameters.Add(":REQUEST_IDs", OracleDbType.Int32, REQUEST_IDs, System.Data.ParameterDirection.Output);
    However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
    Please help me resolve this error or I would appreciate a different solution
    Thank you

    It seems you are not doing a bulk insert but rather an array bind.
    (Which you will also find that it is problematic to do an INSERT with a bulk collect returning clause (while this works just fine for update/deletes) :
    http://www.oracle-developer.net/display.php?id=413)
    But you are using array bind, so you simply just need to use a
    ... Returning REQUEST_ID INTO :REQUEST_IDand that'll return you a Rquest_ID[]
    see below for a working example (I used a procedure but the result is the same)
    //Create Table Zzztab(Deptno Number, Deptname Varchar2(50) , Loc Varchar2(50) , State Varchar2(2) , Idno Number(10)) ;
    //create sequence zzzseq ;
    //CREATE OR REPLACE PROCEDURE ZZZ( P_DEPTNO   IN ZZZTAB.DEPTNO%TYPE,
    //                      P_DEPTNAME IN ZZZTAB.DEPTNAME%TYPE,
    //                      P_LOC      IN ZZZTAB.LOC%TYPE,
    //                      P_State    In Zzztab.State%Type ,
    //                      p_idno     out zzztab.idno%type
    //         IS
    //Begin
    //      Insert Into Zzztab (Deptno,   Deptname,   Loc,   State , Idno)
    //                  Values (P_Deptno, P_Deptname, P_Loc, P_State, Zzzseq.Nextval)
    //                  returning idno into p_idno;
    //END ZZZ;
    //Drop Procedure Zzz ;
    //Drop Sequence Zzzseq ;
    //drop Table Zzztab;
      class ArrayBind
        static void Main(string[] args)
          // Connect
            string connectStr = GetConnectionString();
          // Setup the Tables for sample
          Setup(connectStr);
          // Initialize array of data
          int[]    myArrayDeptNo   = new int[3]{1, 2, 3};
          String[] myArrayDeptName = {"Dev", "QA", "Facility"};
          String[] myArrayDeptLoc  = {"New York", "Chicago", "Texas"};
          String[] state = {"NY","IL","TX"} ;
          OracleConnection connection = new OracleConnection(connectStr);
          OracleCommand    command    = new OracleCommand (
            "zzz", connection);
          command.CommandType = CommandType.StoredProcedure;
          // Set the Array Size to 3. This applied to all the parameter in
          // associated with this command
          command.ArrayBindCount = 3;
          command.BindByName = true;
          // deptno parameter
          OracleParameter deptNoParam = new OracleParameter("p_deptno",OracleDbType.Int32);
          deptNoParam.Direction       = ParameterDirection.Input;
          deptNoParam.Value           = myArrayDeptNo;
          command.Parameters.Add(deptNoParam);
          // deptname parameter
          OracleParameter deptNameParam = new OracleParameter("p_deptname", OracleDbType.Varchar2);
          deptNameParam.Direction       = ParameterDirection.Input;
          deptNameParam.Value           = myArrayDeptName;
          command.Parameters.Add(deptNameParam);
          // loc parameter
          OracleParameter deptLocParam = new OracleParameter("p_loc", OracleDbType.Varchar2);
          deptLocParam.Direction       = ParameterDirection.Input;
          deptLocParam.Value           = myArrayDeptLoc;
          command.Parameters.Add(deptLocParam);
          //P_STATE -- -ARRAY
          OracleParameter stateParam = new OracleParameter("P_STATE", OracleDbType.Varchar2);
          stateParam.Direction = ParameterDirection.Input;
          stateParam.Value = state;
          command.Parameters.Add(stateParam);
                  //idParam-- ARRAY
          OracleParameter idParam = new OracleParameter("p_idno", OracleDbType.Int64 );
          idParam.Direction = ParameterDirection.Output ;
          idParam.OracleDbTypeEx = OracleDbType.Int64;
          command.Parameters.Add(idParam);
          try
            connection.Open();
            command.ExecuteNonQuery ();
            Console.WriteLine("{0} Rows Inserted", command.ArrayBindCount);
              //now cycle through the output param array
            foreach (Int64 i in (Int64[])idParam.Value)
                Console.WriteLine(i);
          catch (Exception e)
            Console.WriteLine("Execution Failed:" + e.Message);
          finally
            // connection, command used server side resource, dispose them
            // asap to conserve resource
            connection.Close();
            command.Dispose();
            connection.Dispose();
          Console.WriteLine("Press Enter to finish");
          Console.ReadKey();
        }

  • Bulk collect into statement

    Hello All,
    I am trying to copy data using database link.
    I am using Oracle 11g on Windows.
    I check data in source table and it exists. When I execute below block it successfully executes but return no data in target database.
    SET SERVEROUTPUT ON
    DECLARE
      TYPE t_bulk_collect_test_1 IS TABLE OF NT_PROP%ROWTYPE;
      l_tab1 t_bulk_collect_test_1;
      CURSOR c_data1 IS
        SELECT *
        FROM NT_PROP@dp_copy;
    BEGIN
      OPEN c_data1;
      LOOP
        FETCH c_data1
        BULK COLLECT INTO l_tab1 LIMIT 10000;
        commit;
      EXIT WHEN l_tab1.count = 0;
      END LOOP;
      CLOSE c_data1;
    END;
    Could someone please let me know what is the eror in this code.
    Thanks in advance

    I think you are expecting BULK INSERT using FORALL. Please see below example.
    See below link also
    http://www.oracle-base.com/articles/9i/bulk-binds-and-record-processing-9i.php#save_exceptions
    DECLARE
      TYPE t_bulk_collect_test_1 IS TABLE OF NT_PROP%ROWTYPE;
      l_tab1 t_bulk_collect_test_1;
      CURSOR c_data1 IS
        SELECT *
        FROM NT_PROP@dp_copy;
        ex_dml_errors EXCEPTION;
         PRAGMA EXCEPTION_INIT(ex_dml_errors, -24381);
    BEGIN
      OPEN c_data1;
      LOOP
        FETCH c_data1
        BULK COLLECT INTO l_tab1 LIMIT 10000;
        BEGIN
          forall i in l_tab1.first..l_tab1.count  save exceptions
           insert into target_tab values l_tab1(i);
        EXCEPTION
              WHEN ex_dml_errors THEN
              l_error_count := SQL%BULK_EXCEPTIONS.count;
              DBMS_OUTPUT.put_line('Number of failures: ' || l_error_count);
          FOR i IN 1 .. l_error_count LOOP
            DBMS_OUTPUT.put_line('Error: ' || i ||
              ' Array Index: ' || SQL%BULK_EXCEPTIONS(i).error_index ||
              ' Message: ' || SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
          END LOOP;
        END;
      EXIT WHEN l_tab1.count = 0;
      END LOOP;
      CLOSE c_data1;
    END;
    Cheers,
    Suri

  • Bulk collect into using vector in where clause

    Hi,
    I have a java stored procedure which takes an array as input and returns an array as output.
    I want to select a column in to a collection of array, using array as the select criteria.
    For example
    create or replace type My_list as table of varchar(20);
    create or replace type outarray as table of BLOB;
    create or replace function myfunction ( inputlist My_list)
    return outarray
    AS
    o_data := outarray();
    BEGIN
    SELECT mycolumn from mytable BULK COLLECT INTO o_data where my_creteria=inputlist
    retrun o_data;
    END;
    Unless I use FORALL I can not retrieve the inputlist values. I am not sure how I can use the bulk collect and forall in the same statement?
    My data is arranged such that , for each value in the inputlist one row will be fetched. I want to fetch all these rows at one go using the inputlist as select criteria,
    I can use the for i in inputlist.first .. inputlist.LAST and iterate the inputlist but that process is quite expensive interms of the latency.
    You help in optimizing my query would be highly appreciated.
    Regards,
    Syam

    That only leaves ugly solutions, like:
    <ul>
    <li>Using dynamic SQL to create a temporary table, doing a bulk insert of the incoming array and then reading the table values using a subquery with the IN opeartor.</li>
    <li>Building a dyanmic list, like ('value1','value2', ..) and use it with the IN operator, this is a variable list and requires DBMS_SQL package.</li>
    <li>Ignore the bulk operations. :-(</li>
    </ul>

  • Error in bulk collect into nested table

    I keep getting an error while trying to compile this line:
    fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);
    LINE/COL ERROR
    0/0      PLS-00801: internal error [74306]When i put that single line into comments it goes fine. Sure it doesn't do what I want.
    The data structure i use is as follows:
      cursor c_juros(p_ind_segreg in varchar2) is
        select (((power(1 + (i.prc_juros_atuari_ano / 100), 1 / 12) - 1) * 100) / 100) prc_juros_efetiv_mes,
               i.dat_inic_vigenc,
               (nvl(i.dat_fim_vigenc, sysdate) + 1) dat_fim_vigenc,
               i.ind_segreg
          from v_indexador_taxa_atuarial i
         where i.ind_segreg = p_ind_segreg
         order by i.dat_inic_vigenc;
      type t_juros_plano     is table of c_juros%rowtype;
      type t_tab_juros_plano is table of t_juros_plano index by binary_integer;
      wrk_juros_plano t_tab_juros_plano;the code goes like this:
      begin
        if not(wrk_juros_plano.exists(p_ind_segreg))
        then
          if c_juros%isopen
          then
            close c_juros;
          end if;
          open c_juros(p_ind_segreg);
          wrk_juros_plano(p_ind_segreg) := t_juros_plano();
          fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);
        end if;
      ...p_ind_segreg is my input parameter, that should be the index of the array.
    The purpose is to create the parameter indexed element if it doesn't already exist, fetching it
    from the cursor, that defines a nested table.
    I tried removing the initialization line to no effect, among other things.

    Ok, I just found out a way around it. It works, but that error is probably a bug, cause workarounds are not really cute.
    I declared a nested table compatible with the element from the associative array:
    wrk_juros t_juros_plano;and chaged that line that was causing the error
    fetch c_juros bulk collect into wrk_juros_plano(p_ind_segreg);for
    fetch c_juros bulk collect into wrk_juros;
    wrk_juros_plano(p_ind_segreg) := wrk_juros;Awesome =\

  • ORA-22167 when using RETURNING... BULK COLLECT INTO feature

    I posted this on the General Board, but I'm still having the issue. Any help would be appreciated!
    I'm loading raw data into a staging table, and want to perform a series of validations before moving it into the system. Records that fail are marked invalid in the stage table, and then an error message written to another table. When updating the 'invalid' flag in the (database) stage table, I return the record identifier into a pl/sql table, then iterate through said table to insert into my (database) error table. This works great for my first validation, but when I use the pl/sql table for the second validation, I get ORA-22167, which basically complains about the subscript supplied to TRIM being out of range. I've tried DELETEing the pl/sql table, setting it to NULL, re-initializing it... none of which works. I have also tried using a brand new table for each validation, but I still get the same message. What am I missing?
    Psuedo-code is like this (please ignore any syntax errors... real code is syntactically correct) :
    DECLARE
    TYPE RECORD_SEQ_TBL IS TABLE OF fcsf_arc.record_seq_nbr%TYPE;
    lt_bad_fcsf_tbl RECORD_SEQ_TBL := NULL;
    BEGIN
    UPDATE <stg_tbl>
    SET valid_ind = 'N'
    WHERE <error condition 1>
    RETURNING seq_nbr BULK COLLECT INTO lt_bad_fcsf_tbl;
    FORALL j IN lt_bad_fcsf_tbl.FIRST..lt_bad_fcsf_tbl.LAST
    INSERT INTO <error_tbl>
    VALUES ('message', lt_bad_fcsf_tbl(j));
    -- works ok so far...
    -- I've tried various combinations of the next three comments to no avail (including doing nothing at all)
    -- lt_bad_fcsf_tbl.DELETE;
    -- lt_bad_fcsf_tbl := NULL;
    -- lt_bad_fcsf_tbl := RECORD_SEQ_TBL();
    -- now I want to do my second validation
    UPDATE <stg_tbl>
    SET valid_ind = 'N'
    WHERE <error condition 2>
    RETURNING seq_nbr BULK COLLECT INTO lt_bad_fcsf_tbl;
    -- and THAT is where I get the ORA-22167

    Thanks for the pointer, Sy. I'm trying to track down soembody with a valid metalink account... everybody I know that has one is getting 'invalid login' messages.
    In the meantime, I have switched from nested tables to associative arrays, and this change seems to be working (so far).
    Thanks again for your feedback!

  • Use of FOR Cursor and BULK COLLECT INTO

    Dear all,
    in which case we prefer to use FOR cursor and cursor with BULK COLLECT INTO? The following contains two block that query identically where one is using FOR cursor, the other is using BULK COLLECT INTO . Which one that performs better given in the existing task? How do we measure performance between these two?
    I'm using sample HR schema:
    declare
    l_start number;
    BEGIN
    l_start:= DBMS_UTILITY.get_time;
    dbms_lock.sleep(1);
    FOR employee IN (SELECT e.last_name, j.job_title FROM employees e,jobs j
    where e.job_id=j.job_id and  e.job_id LIKE '%CLERK%' AND e.manager_id > 120 ORDER BY e.last_name)
    LOOP
      DBMS_OUTPUT.PUT_LINE ('Name = ' || employee.last_name || ', Job = ' || employee.job_title);
    END LOOP;
    DBMS_OUTPUT.put_line('total time: ' || to_char(DBMS_UTILITY.get_time - l_start) || ' hsecs');
    END;
    declare
    l_start number;
    type rec_type is table of varchar2(20);
    name_rec rec_type;
    job_rec rec_type;
    begin
    l_start:= DBMS_UTILITY.get_time;
    dbms_lock.sleep(1);
    SELECT e.last_name, j.job_title bulk collect into name_rec,job_rec FROM employees e,jobs j
    where e.job_id=j.job_id and  e.job_id LIKE '%CLERK%' AND e.manager_id > 120 ORDER BY e.last_name;
    for j in name_rec.first..name_rec.last loop
      DBMS_OUTPUT.PUT_LINE ('Name = ' || name_rec(j) || ', Job = ' || job_rec(j));
    END LOOP;
    DBMS_OUTPUT.put_line('total time: ' || to_char(DBMS_UTILITY.get_time - l_start) || ' hsecs');
    end;
    /In this code, I put timestamp in each block, but they are useless since they both run virtually instantaneous...
    Best regards,
    Val

    If you want to get 100% benifit of bulk collect then it must be implemented as below
    declare
         Cursor cur_emp
         is
         SELECT     e.last_name, j.job_title
         FROM     employees e,jobs j
         where     e.job_id=j.job_id
                   and  e.job_id LIKE '%CLERK%'
                   AND e.manager_id > 120
         ORDER BY e.last_name;
         l_start number;
         type rec_type is table of varchar2(20);
         name_rec rec_type;
         job_rec rec_type;
    begin
         l_start:= DBMS_UTILITY.get_time;
         dbms_lock.sleep(1);
         /*SELECT e.last_name, j.job_title bulk collect into name_rec,job_rec FROM employees e,jobs j
         where e.job_id=j.job_id and  e.job_id LIKE '%CLERK%' AND e.manager_id > 120 ORDER BY e.last_name;
         OPEN cur_emp;
         LOOP
              FETCH cur_emp BULK COLLECT INTO name_rec LIMIT 100;
              EXIT WHEN name_rec.COUNT=0;
              FOR j in 1..name_rec.COUNT
              LOOP
                   DBMS_OUTPUT.PUT_LINE ('Name = ' || name_rec(j) || ', Job = ' || job_rec(j));          
              END LOOP;
              EXIT WHEN cur_emp%NOTFOUND;
         END LOOP;
            CLOSE cur_emp;
         DBMS_OUTPUT.put_line('total time: ' || to_char(DBMS_UTILITY.get_time - l_start) || ' hsecs');
    end;
    /

  • Procedure failed while using bulk collect into clause and works with cursor

    hi all,
    I am using "BULK collect into" clause in my procedure and it is failing after 21 minutes and gives the error "end of file communication channel".
    after this error comes when i tried to connect database it is giving following error.
    ORA -01034 - Oracle not available.
    ORA- 27101 - shared memory realm does not exist.
    svr4- error :2 : No such file or directory.
    when i use cursor instead of BULK COLLECT INTO clause it is running successful.
    Following code is working with cursor.
    procedure work_kiosk_full(an_jobid in number ,ac_sqlcode out varchar2 ,ac_sqlerrm out varchar2) is
    ld_curr_time Date;
    cursor cur_work_kiosk is
    select distinct jt.jt_id AS jt_id,
    NVL ((ROUND ((jt_date_completed - jt_date_requested) * 24, 2)
    0
    ) AS actual_hrs_to_complete,
    NVL ((ROUND ((jt_date_responded - jt_date_requested) * 24, 2)
    0
    ) AS actual_hrs_to_respond,
    peo1.peo_name AS agent_name,
    peo1.peo_user_name AS asagent_soe_id,
    le.lglent_desc AS ap_system,
    ' ' AS assign_work_request_comment,
    DECODE (jt.jt_bill_id,
    138802, 'CLIENT BILLABLE',
    138803, 'CONTRACTED',
    138804, 'INTERNAL BILLABLE',
    NULL, ' '
    ) AS billable,
    bl.bldg_name_cc AS building, bl.bldg_id_ls AS building_id,
    DECODE (bl.bldg_active_cc,
    'Y', 'ACTIVE',
    'INACTIVE'
    ) AS building_status,
    DECODE (jt.jt_wrk_cause_id,
    141521, 'STANDARD WEAR AND TEAR',
    141522, 'NEGLIGENCE',
    141523, 'ACCIDENTAL',
    141524, 'MECHANICAL MALFUNCTION',
    141525, 'OVERSIGHT',
    141526, 'VANDAL',
    141527, 'STANDARD',
    141528, 'PROJECT WORK',
    6058229, 'TEST',
    NULL, ' '
    ) AS cause_type,
    ' ' AS comments, peo3.peo_name AS completed_by,
    jt.jt_requestor_email AS contact_email,
    jt.jt_requestor_name_first
    || ' '
    || jt.jt_requestor_name_last AS contact_name,
    jt.jt_requestor_phone AS contact_phone,
    cc.cstctrcd_apcode AS corp_code,
    cc.cstctrcd_code AS cost_center,
    jt.jt_date_closed AS date_closed,
    jt.jt_date_completed AS date_completed,
    jt.jt_date_requested AS date_requested,
    jt.jt_date_responded AS date_responded,
    jt.jt_date_response_ecd AS date_response_ecd,
    jt.jt_date_scheduled AS date_scheduled,
    DECODE (jt.jt_def_id,
    139949, 'WTG VENDOR RESPONSE',
    139950, 'WAITING ON PARTS',
    139951, 'LABOR AVAILABILITY',
    139952, 'DEFERRED- HI PRI WORK',
    139953, 'WTG APPROVAL',
    139954, 'FUNDING REQUIRED',
    139955, 'ACCESS DENIED',
    139956, 'WTG MATERIAL',
    NULL, ' '
    ) AS deferral_reason,
    jt.jt_description AS description,
    jt.jt_date_resched_ecd AS ecd,
    fmg.facility_manager AS facility_manager,
    fl.floors_text AS FLOOR, gl.genled_desc AS general_ledger,
    ' ' AS kiosk_date_requested, ' ' AS kiosk_dispatch_confirmed,
    ' ' AS kiosk_dispatched,
    eqp.equip_customer_code AS linked_equipment_alias,
    eqp.equip_id AS linked_equipment_id,
    eqp.equip_text AS linked_equipment_name,
    DECODE (jt_originator_type_id,
    1000, 'PROJECT MOVE REQUEST',
    138834, 'CUSTOMER INITIATED CORRECTION',
    138835, 'CUSTOMER INITIATED REQUEST',
    138836, 'CORRECTIVE MAINTENANCE',
    138837, 'CONFERENCE ROOM BOOKING',
    138838, 'PROJECT INITIATED REQUEST',
    138839, 'PLANNED PREVENTIVE MAINTENANCE',
    138840, 'SELF INITATED REQUEST',
    NULL, ' '
    ) AS originator_type,
    ' ' AS payment_terms, priority_text AS priority_code,
    swoty.sworktype_text AS problem_type,
    prop.property_name_cc AS property,
    jt.jt_cost_quote_total AS quote_total,
    par.levels_name AS region,
    DECODE (jt.jt_repdef_id,
    141534, 'ADJUSTED SETTING',
    141535, 'TRAINING FOR END',
    141536, 'NEW REQUEST',
    141537, 'NO REPAIR REQUIR',
    141538, 'REPLACED PARTS',
    141539, 'REPLACE EQUIPMEN',
    1000699, 'NEW REQUEST',
    NULL, ' '
    ) AS repair_definitions,
    jt.jt_repairdesc AS repair_description,
    jt.jt_requestor AS requestor, ' ' AS requestor_cost_center,
    jt.jt_requestor_email AS requestor_email,
    jt.jt_requestor_name_first AS requestor_name,
    jt.jt_requestor_phone AS requestor_phone,
    ' ' AS response_time, rm.room_name_cc AS room,
    p1.peo_provider_code1 AS service_provider,
    p1.peo_address_1 AS service_provider_address,
    peocity.city_text service_provider_city,
    p1.peo_provider_code1 AS service_provider_code,
    peocity.city_country_name AS service_provider_country,
    peocur.currency_text AS service_provider_currency,
    p1.peo_name AS service_provider_description,
    p1.peo_dispatch_method AS serv_prov_dispatc_hmethod,
    p1.peo_rate_double AS serv_prov_double_time_rate,
    p1.peo_email AS service_provider_email,
    p1.peo_emergency_phone AS serv_prov_emergency_phone,
    p1.peo_fax AS service_provider_fax_number,
    p1.peo_home_phone AS service_provider_home_phone,
    p1.peo_rate_hourly AS service_provider_hourly_rate,
    p1.peo_title AS service_provider_job_title,
    p1.peo_method_id AS service_provider_method,
    p1.peo_cell_phone AS service_provider_mobile_phone,
    p1.peo_pager AS service_provider_pager,
    p1.peo_rate_differential AS service_provider_rates,
    p1.peo_rate_differential AS ser_prov_shift_differential,
    peocity.city_state_prov_text AS serv_prov_state_province,
    DECODE (p1.peo_active,
    'Y', 'ACTIVE',
    'INACTIVE'
    ) AS service_provider_status,
    p1.peo_url AS serv_prov_web_site_address,
    p1.peo_phone AS service_provider_work_phone,
    p1.peo_postal_code AS serv_prov_zip_postal_code, ' ' AS shift,
    ' ' AS skill,
    DECODE (jt.jt_bigstatus_id,
    138813, 'NEW',
    138814, 'PENDING',
    138815, 'OPEN',
    138816, 'COMPLETED',
    138817, 'CLOSED',
    138818, 'CANCELLED',
    NULL, ' '
    ) AS status,
    lev.levels_name AS subregion, ' ' AS trade,
    p1.peo_ls_interface_code1 AS vendor_id,
    p1.peo_fax AS vendor_purchasing_fax,
    p1.peo_vendor_site_code AS vendor_sitecode,
    jt.jt_id AS vendor_ticket, p1.peo_name AS vendor_companyname,
    jt.jt_requestor_vip AS vip, wo.wo_id AS work_order_no,
    jt.jt_id AS work_request,
    jt.jt_class_id AS work_request_class,
    woty.worktype_text AS work_type, ' ' AS wr_cost,
    jt.jt_description AS wr_description,
    ' ' AS wr_dispatch_method,
    DECODE (jt.jt_bigstatus_id,
    138813, 'NEW',
    138814, 'PENDING',
    138815, 'OPEN',
    138816, 'COMPLETED',
    138817, 'CLOSED',
    138818, 'CANCELLED',
    NULL, ' '
    ) AS wr_status,
    ctry.country_name AS country
    FROM citi.jobticket jt,
    citi.property prop,
    citi.bldg bl,
    citi.bldg_levels bldglvl,
    citi.LEVELS lev,
    citi.LEVELS par,
    (SELECT crstools.stragg (peo_name) facility_manager,
    bldgcon_bldg_id
    FROM citi.bldg_contacts, citi.people
    WHERE bldgcon_peo_id = peo_id
    AND bldgcon_contype_id IN (40181, 10142)
    GROUP BY bldgcon_bldg_id) fmg,
    citi.floors fl,
    citi.room rm,
    citi.general_ledger gl,
    citi.legal_entity le,
    citi.cost_center_codes cc,
    citi.equipment eqp,
    citi.worktype woty,
    citi.subworktype swoty,
    citi.work_order wo,
    citi.jt_workers jtwo,
    citi.priority,
    citi.country ctry,
    citi.people p1,
    citi.people peo3,
    citi.people peo1,
    citi.city peocity,
    citi.currency peocur
    WHERE jt.jt_bldg_id = bl.bldg_id
    AND bl.bldg_id = bldglvl.bldg_levels_bldg_id
    AND bldglvl.bldg_levels_levels_id = lev.levels_id
    AND lev.levels_parent = par.levels_id(+)
    AND prop.property_id = bl.bldg_property_id
    AND bl.bldg_active_ls <> 'N'
    AND jt.jt_floors_id = fl.floors_id(+)
    AND jt.jt_room_id = rm.room_id(+)
    AND jt.jt_bldg_id = fmg.bldgcon_bldg_id(+)
    AND jt.jt_genled_id = gl.genled_id(+)
    AND gl.genled_lglent_id = le.lglent_id(+)
    AND jt.jt_cstctrcd_id = cc.cstctrcd_id(+)
    AND jt.jt_equip_id = eqp.equip_id(+)
    AND jt.jt_id = jtwo.jtw_jt_id(+)
    AND jt.jt_worktype_id = woty.worktype_id(+)
    AND jt.jt_sworktype_id = swoty.sworktype_id(+)
    AND jt.jt_wo_id = wo.wo_id
    AND jt.jt_priority_id = priority_id(+)
    --AND jt.jt_date_requested >= ADD_MONTHS (SYSDATE, -12)
    AND jt.jt_last_update >= ADD_MONTHS (ld_curr_time, -12)
    AND bl.bldg_country_id = ctry.country_id
    AND jtwo.jtw_peo_id = p1.peo_id(+)
    AND p1.peo_city_id = peocity.city_id(+)
    AND jt.jt_completed_by_peo_id = peo3.peo_id(+)
    AND p1.peo_rate_currency_id = peocur.currency_id(+)
    AND jt.jt_agent_peo_id = peo1.peo_id(+);
    BEGIN
    execute immediate 'truncate table crstools.drt_bom_work_kiosk';
    select sysdate into ld_curr_time from dual;
    FOR cur_rec in cur_work_kiosk LOOP
    IF MOD(cur_work_kiosk%rowcount,10000 ) = 0 then
    COMMIT;
    END IF;
    INSERT INTO crstools.drt_bom_work_kiosk
    ( JT_ID
    ,ACTUAL_HRS_TO_COMPLETE
    ,ACTUAL_HRS_TO_RESPOND
    ,AGENT_NAME
    ,ASAGENT_SOE_ID
    ,AP_SYSTEM
    ,ASSIGN_WORK_REQUEST_COMMENT
    ,BILLABLE
    ,BUILDING
    ,BUILDING_ID
    ,BUILDING_STATUS
    ,CAUSE_TYPE
    ,COMMENTS
    ,COMPLETED_BY
    ,CONTACT_EMAIL
    ,CONTACT_NAME
    ,CONTACT_PHONE
    ,CORP_CODE
    ,COST_CENTER
    ,DATE_CLOSED
    ,DATE_COMPLETED
    ,DATE_REQUESTED
    ,DATE_RESPONDED
    ,DATE_RESPONSE_ECD
    ,DATE_SCHEDULED
    ,DEFERRAL_REASON
    ,DESCRIPTION
    ,ECD
    ,FACILITY_MANAGER
    ,FLOOR
    ,GENERAL_LEDGER
    ,KIOSK_DATE_REQUESTED
    ,KIOSK_DISPATCH_CONFIRMED
    ,KIOSK_DISPATCHED
    ,LINKED_EQUIPMENT_ALIAS
    ,LINKED_EQUIPMENT_ID
    ,LINKED_EQUIPMENT_NAME
    ,ORIGINATOR_TYPE
    ,PAYMENT_TERMS
    ,PRIORITY_CODE
    ,PROBLEM_TYPE
    ,PROPERTY
    ,QUOTE_TOTAL
    ,REGION
    ,REPAIR_DEFINITIONS
    ,REPAIR_DESCRIPTION
    ,REQUESTOR
    ,REQUESTOR_COST_CENTER
    ,REQUESTOR_EMAIL
    ,REQUESTOR_NAME
    ,REQUESTOR_PHONE
    ,RESPONSE_TIME
    ,ROOM
    ,SERVICE_PROVIDER
    ,SERVICE_PROVIDER_ADDRESS
    ,SERVICE_PROVIDER_CITY
    ,SERVICE_PROVIDER_CODE
    ,SERVICE_PROVIDER_COUNTRY
    ,SERVICE_PROVIDER_CURRENCY
    ,SERVICE_PROVIDER_DESCRIPTION
    ,SERV_PROV_DISPATC_HMETHOD
    ,SERV_PROV_DOUBLE_TIME_RATE
    ,SERVICE_PROVIDER_EMAIL
    ,SERV_PROV_EMERGENCY_PHONE
    ,SERVICE_PROVIDER_FAX_NUMBER
    ,SERVICE_PROVIDER_HOME_PHONE
    ,SERVICE_PROVIDER_HOURLY_RATE
    ,SERVICE_PROVIDER_JOB_TITLE
    ,SERVICE_PROVIDER_METHOD
    ,SERVICE_PROVIDER_MOBILE_PHONE
    ,SERVICE_PROVIDER_PAGER
    ,SERVICE_PROVIDER_RATES
    ,SER_PROV_SHIFT_DIFFERENTIAL
    ,SERV_PROV_STATE_PROVINCE
    ,SERVICE_PROVIDER_STATUS
    ,SERV_PROV_WEB_SITE_ADDRESS
    ,SERVICE_PROVIDER_WORK_PHONE
    ,SERV_PROV_ZIP_POSTAL_CODE
    ,SHIFT
    ,SKILL
    ,STATUS
    ,SUBREGION
    ,TRADE
    ,VENDOR_ID
    ,VENDOR_PURCHASING_FAX
    ,VENDOR_SITECODE
    ,VENDOR_TICKET
    ,VENDOR_COMPANYNAME
    ,VIP
    ,WORK_ORDER_NO
    ,WORK_REQUEST
    ,WORK_REQUEST_CLASS
    ,WORK_TYPE
    ,WR_COST
    ,WR_DESCRIPTION
    ,WR_DISPATCH_METHOD
    ,WR_STATUS
    ,COUNTRY
    ,CREATE_DATE
    VALUES
    (cur_rec.jt_id
    ,cur_rec.ACTUAL_HRS_TO_COMPLETE
    ,cur_rec.ACTUAL_HRS_TO_RESPOND
    ,cur_rec.AGENT_NAME
    ,cur_rec.ASAGENT_SOE_ID
    ,cur_rec.AP_SYSTEM
    ,cur_rec.ASSIGN_WORK_REQUEST_COMMENT
    ,cur_rec.BILLABLE
    ,cur_rec.BUILDING
    ,cur_rec.BUILDING_ID
    ,cur_rec.BUILDING_STATUS
    ,cur_rec.CAUSE_TYPE
    ,cur_rec.COMMENTS
    ,cur_rec.COMPLETED_BY
    ,cur_rec.CONTACT_EMAIL
    ,cur_rec.CONTACT_NAME
    ,cur_rec.CONTACT_PHONE
    ,cur_rec.CORP_CODE
    ,cur_rec.COST_CENTER
    ,cur_rec.DATE_CLOSED
    ,cur_rec.DATE_COMPLETED
    ,cur_rec.DATE_REQUESTED
    ,cur_rec.DATE_RESPONDED
    ,cur_rec.DATE_RESPONSE_ECD
    ,cur_rec.DATE_SCHEDULED
    ,cur_rec.DEFERRAL_REASON
    ,cur_rec.DESCRIPTION
    ,cur_rec.ECD
    ,cur_rec.FACILITY_MANAGER
    ,cur_rec.FLOOR
    ,cur_rec.GENERAL_LEDGER
    ,cur_rec.KIOSK_DATE_REQUESTED
    ,cur_rec.KIOSK_DISPATCH_CONFIRMED
    ,cur_rec.KIOSK_DISPATCHED
    ,cur_rec.LINKED_EQUIPMENT_ALIAS
    ,cur_rec.LINKED_EQUIPMENT_ID
    ,cur_rec.LINKED_EQUIPMENT_NAME
    ,cur_rec.ORIGINATOR_TYPE
    ,cur_rec.PAYMENT_TERMS
    ,cur_rec.PRIORITY_CODE
    ,cur_rec.PROBLEM_TYPE
    ,cur_rec.PROPERTY
    ,cur_rec.QUOTE_TOTAL
    ,cur_rec.REGION
    ,cur_rec.REPAIR_DEFINITIONS
    ,cur_rec.REPAIR_DESCRIPTION
    ,cur_rec.REQUESTOR
    ,cur_rec.REQUESTOR_COST_CENTER
    ,cur_rec.REQUESTOR_EMAIL
    ,cur_rec.REQUESTOR_NAME
    ,cur_rec.REQUESTOR_PHONE
    ,cur_rec.RESPONSE_TIME
    ,cur_rec.ROOM
    ,cur_rec.SERVICE_PROVIDER
    ,cur_rec.SERVICE_PROVIDER_ADDRESS
    ,cur_rec.SERVICE_PROVIDER_CITY
    ,cur_rec.SERVICE_PROVIDER_CODE
    ,cur_rec.SERVICE_PROVIDER_COUNTRY
    ,cur_rec.SERVICE_PROVIDER_CURRENCY
    ,cur_rec.SERVICE_PROVIDER_DESCRIPTION
    ,cur_rec.SERV_PROV_DISPATC_HMETHOD
    ,cur_rec.SERV_PROV_DOUBLE_TIME_RATE
    ,cur_rec.SERVICE_PROVIDER_EMAIL
    ,cur_rec.SERV_PROV_EMERGENCY_PHONE
    ,cur_rec.SERVICE_PROVIDER_FAX_NUMBER
    ,cur_rec.SERVICE_PROVIDER_HOME_PHONE
    ,cur_rec.SERVICE_PROVIDER_HOURLY_RATE
    ,cur_rec.SERVICE_PROVIDER_JOB_TITLE
    ,cur_rec.SERVICE_PROVIDER_METHOD
    ,cur_rec.SERVICE_PROVIDER_MOBILE_PHONE
    ,cur_rec.SERVICE_PROVIDER_PAGER
    ,cur_rec.SERVICE_PROVIDER_RATES
    ,cur_rec.SER_PROV_SHIFT_DIFFERENTIAL
    ,cur_rec.SERV_PROV_STATE_PROVINCE
    ,cur_rec.SERVICE_PROVIDER_STATUS
    ,cur_rec.SERV_PROV_WEB_SITE_ADDRESS
    ,cur_rec.SERVICE_PROVIDER_WORK_PHONE
    ,cur_rec.SERV_PROV_ZIP_POSTAL_CODE
    ,cur_rec.SHIFT
    ,cur_rec.SKILL
    ,cur_rec.STATUS
    ,cur_rec.SUBREGION
    ,cur_rec.TRADE
    ,cur_rec.VENDOR_ID
    ,cur_rec.VENDOR_PURCHASING_FAX
    ,cur_rec.VENDOR_SITECODE
    ,cur_rec.VENDOR_TICKET
    ,cur_rec.VENDOR_COMPANYNAME
    ,cur_rec.VIP
    ,cur_rec.WORK_ORDER_NO
    ,cur_rec.WORK_REQUEST
    ,cur_rec.WORK_REQUEST_CLASS
    ,cur_rec.WORK_TYPE
    ,cur_rec.WR_COST
    ,cur_rec.WR_DESCRIPTION
    ,cur_rec.WR_DISPATCH_METHOD
    ,cur_rec.WR_STATUS
    ,cur_rec.COUNTRY
    ,ld_curr_time
    END LOOP;
    COMMIT;
    exception
    when others then
    rollback;
    dbms_output.put_line('SQLCODE :'||sqlcode ||' Error :'||sqlerrm);
    end work_kiosk_full;
    Note : total record inserted 849000.
    The same code does not work with bulk collect into caluse.
    Please help me out why this is happening.
    Thanks & regards
    shyam~

    Shyam,
    I agree with Billy.
    Why are you not using an INSERT..SELECT ?
    Also, what are you trying to achieve by
    - incremental commits?
    - copying data from one table to another (using expensive I/O)?
    - using dynamic DML?
    Most of these approaches are typically wrong - and not recommended for scalable and performant Oracle applications.I could see you using a CURSOR FOR LOOP if you were changing the data being inserted in such a way that you couldn't encapsulate the changes in a query, but you are doing a straight insert into the table from your Cursor. A much more efficient way would be to use the following modifications I made to your code example:
    PROCEDURE WORK_KIOSK_FULL(AN_JOBID   IN NUMBER,
                              AC_SQLCODE OUT VARCHAR2,
                              AC_SQLERRM OUT VARCHAR2) IS
    BEGIN
       EXECUTE IMMEDIATE 'truncate table crstools.drt_bom_work_kiosk';
       /* Note:  The APPEND hint forces a Direct Path INSERT (see Link below code sample) and is combined with the NOLOGGING Hint */
       /*        To dramtically increase performance.  The Direct Path INSERT inserts records above the High-Water Mark on the table. */
       INSERT /*+ APPEND NOLOGGING */ INTO CRSTOOLS.DRT_BOM_WORK_KIOSK
          (JT_ID
          ,ACTUAL_HRS_TO_COMPLETE
          ,ACTUAL_HRS_TO_RESPOND
          ,AGENT_NAME
          ,ASAGENT_SOE_ID
          ,AP_SYSTEM
    --      ,ASSIGN_WORK_REQUEST_COMMENT     /* I commented out this COLUMN because it doesn't make sense to me to insert */
          ,BILLABLE                          /* a couple of space characters into a table.   If the intent is to leave the column NULL */
          ,BUILDING                          /* don't include it in your INSERT statement and it will be NULL.  If there is a valid reason */
          ,BUILDING_ID                       /* for inserting the spaces, then remove the "line comments" from the insert and select statments */
          ,BUILDING_STATUS
          ,CAUSE_TYPE
    --      ,COMMENTS
          ,COMPLETED_BY
          ,CONTACT_EMAIL
          ,CONTACT_NAME
          ,CONTACT_PHONE
          ,CORP_CODE
          ,COST_CENTER
          ,DATE_CLOSED
          ,DATE_COMPLETED
          ,DATE_REQUESTED
          ,DATE_RESPONDED
          ,DATE_RESPONSE_ECD
          ,DATE_SCHEDULED
          ,DEFERRAL_REASON
          ,DESCRIPTION
          ,ECD
          ,FACILITY_MANAGER
          ,FLOOR
          ,GENERAL_LEDGER
    --      ,KIOSK_DATE_REQUESTED
    --      ,KIOSK_DISPATCH_CONFIRMED
    --      ,KIOSK_DISPATCHED
          ,LINKED_EQUIPMENT_ALIAS
          ,LINKED_EQUIPMENT_ID
          ,LINKED_EQUIPMENT_NAME
          ,ORIGINATOR_TYPE
    --      ,PAYMENT_TERMS
          ,PRIORITY_CODE
          ,PROBLEM_TYPE
          ,PROPERTY
          ,QUOTE_TOTAL
          ,REGION
          ,REPAIR_DEFINITIONS
          ,REPAIR_DESCRIPTION
          ,REQUESTOR
    --      ,REQUESTOR_COST_CENTER
          ,REQUESTOR_EMAIL
          ,REQUESTOR_NAME
          ,REQUESTOR_PHONE
    --      ,RESPONSE_TIME
          ,ROOM
          ,SERVICE_PROVIDER
          ,SERVICE_PROVIDER_ADDRESS
          ,SERVICE_PROVIDER_CITY
          ,SERVICE_PROVIDER_CODE
          ,SERVICE_PROVIDER_COUNTRY
          ,SERVICE_PROVIDER_CURRENCY
          ,SERVICE_PROVIDER_DESCRIPTION
          ,SERV_PROV_DISPATC_HMETHOD
          ,SERV_PROV_DOUBLE_TIME_RATE
          ,SERVICE_PROVIDER_EMAIL
          ,SERV_PROV_EMERGENCY_PHONE
          ,SERVICE_PROVIDER_FAX_NUMBER
          ,SERVICE_PROVIDER_HOME_PHONE
          ,SERVICE_PROVIDER_HOURLY_RATE
          ,SERVICE_PROVIDER_JOB_TITLE
          ,SERVICE_PROVIDER_METHOD
          ,SERVICE_PROVIDER_MOBILE_PHONE
          ,SERVICE_PROVIDER_PAGER
          ,SERVICE_PROVIDER_RATES
          ,SER_PROV_SHIFT_DIFFERENTIAL
          ,SERV_PROV_STATE_PROVINCE
          ,SERVICE_PROVIDER_STATUS
          ,SERV_PROV_WEB_SITE_ADDRESS
          ,SERVICE_PROVIDER_WORK_PHONE
          ,SERV_PROV_ZIP_POSTAL_CODE
    --      ,SHIFT
    --      ,SKILL
          ,STATUS
          ,SUBREGION
    --      ,TRADE
          ,VENDOR_ID
          ,VENDOR_PURCHASING_FAX
          ,VENDOR_SITECODE
          ,VENDOR_TICKET
          ,VENDOR_COMPANYNAME
          ,VIP
          ,WORK_ORDER_NO
          ,WORK_REQUEST
          ,WORK_REQUEST_CLASS
          ,WORK_TYPE
    --      ,WR_COST
          ,WR_DESCRIPTION
    --      ,WR_DISPATCH_METHOD
          ,WR_STATUS
          ,COUNTRY
          ,CREATE_DATE
       VALUES
          (SELECT DISTINCT
              JT.JT_ID AS JT_ID
             ,NVL((ROUND((JT_DATE_COMPLETED - JT_DATE_REQUESTED) * 24,2)),0) AS ACTUAL_HRS_TO_COMPLETE
             ,NVL((ROUND((JT_DATE_RESPONDED - JT_DATE_REQUESTED) * 24,2)),0) AS ACTUAL_HRS_TO_RESPOND
             ,PEO1.PEO_NAME AS AGENT_NAME
             ,PEO1.PEO_USER_NAME AS ASAGENT_SOE_ID
             ,LE.LGLENT_DESC AS AP_SYSTEM
    --         ,' ' AS ASSIGN_WORK_REQUEST_COMMENT
             ,DECODE(JT.JT_BILL_ID,138802,'CLIENT BILLABLE'
                                  ,138803,'CONTRACTED'
                                  ,138804,'INTERNAL BILLABLE',NULL,' ') AS BILLABLE
             ,BL.BLDG_NAME_CC AS BUILDING
             ,BL.BLDG_ID_LS AS BUILDING_ID
             ,DECODE(BL.BLDG_ACTIVE_CC, 'Y', 'ACTIVE', 'INACTIVE') AS BUILDING_STATUS
             ,DECODE(JT.JT_WRK_CAUSE_ID,141521,'STANDARD WEAR AND TEAR'
                                       ,141522,'NEGLIGENCE'
                                       ,141523,'ACCIDENTAL'
                                       ,141524,'MECHANICAL MALFUNCTION'
                                       ,141525,'OVERSIGHT'
                                       ,141526,'VANDAL'
                                       ,141527,'STANDARD'
                                       ,141528,'PROJECT WORK'
                                       ,6058229,'TEST',NULL,' ') AS CAUSE_TYPE
    --         ,' ' AS COMMENTS
             ,PEO3.PEO_NAME AS COMPLETED_BY
             ,JT.JT_REQUESTOR_EMAIL AS CONTACT_EMAIL
             ,JT.JT_REQUESTOR_NAME_FIRST || ' ' ||JT.JT_REQUESTOR_NAME_LAST AS CONTACT_NAME
             ,JT.JT_REQUESTOR_PHONE AS CONTACT_PHONE
             ,CC.CSTCTRCD_APCODE AS CORP_CODE
             ,CC.CSTCTRCD_CODE AS COST_CENTER
             ,JT.JT_DATE_CLOSED AS DATE_CLOSED
             ,JT.JT_DATE_COMPLETED AS DATE_COMPLETED
             ,JT.JT_DATE_REQUESTED AS DATE_REQUESTED
             ,JT.JT_DATE_RESPONDED AS DATE_RESPONDED
             ,JT.JT_DATE_RESPONSE_ECD AS DATE_RESPONSE_ECD
             ,JT.JT_DATE_SCHEDULED AS DATE_SCHEDULED
             ,DECODE(JT.JT_DEF_ID,139949,'WTG VENDOR RESPONSE'
                                 ,139950,'WAITING ON PARTS'
                                 ,139951,'LABOR AVAILABILITY'
                                 ,139952,'DEFERRED- HI PRI WORK'
                                 ,139953,'WTG APPROVAL'
                                 ,139954,'FUNDING REQUIRED'
                                 ,139955,'ACCESS DENIED'
                                 ,139956,'WTG MATERIAL',NULL,' ') AS DEFERRAL_REASON
             ,JT.JT_DESCRIPTION AS DESCRIPTION
             ,JT.JT_DATE_RESCHED_ECD AS ECD
             ,FMG.FACILITY_MANAGER AS FACILITY_MANAGER
             ,FL.FLOORS_TEXT AS FLOOR
             ,GL.GENLED_DESC AS GENERAL_LEDGER
    --         ,' ' AS KIOSK_DATE_REQUESTED
    --         ,' ' AS KIOSK_DISPATCH_CONFIRMED
    --         ,' ' AS KIOSK_DISPATCHED
             ,EQP.EQUIP_CUSTOMER_CODE AS LINKED_EQUIPMENT_ALIAS
             ,EQP.EQUIP_ID AS LINKED_EQUIPMENT_ID
             ,EQP.EQUIP_TEXT AS LINKED_EQUIPMENT_NAME
             ,DECODE(JT_ORIGINATOR_TYPE_ID,1000,'PROJECT MOVE REQUEST'
                                          ,138834,'CUSTOMER INITIATED CORRECTION'
                                          ,138835,'CUSTOMER INITIATED REQUEST'
                                          ,138836,'CORRECTIVE MAINTENANCE'
                                          ,138837,'CONFERENCE ROOM BOOKING'
                                          ,138838,'PROJECT INITIATED REQUEST'
                                          ,138839,'PLANNED PREVENTIVE MAINTENANCE'
                                          ,138840,'SELF INITATED REQUEST',NULL,' ') AS ORIGINATOR_TYPE
    --         ,' ' AS PAYMENT_TERMS
             ,PRIORITY_TEXT AS PRIORITY_CODE
             ,SWOTY.SWORKTYPE_TEXT AS PROBLEM_TYPE
             ,PROP.PROPERTY_NAME_CC AS PROPERTY
             ,JT.JT_COST_QUOTE_TOTAL AS QUOTE_TOTAL
             ,PAR.LEVELS_NAME AS REGION
             ,DECODE(JT.JT_REPDEF_ID,141534,'ADJUSTED SETTING'
                                    ,141535,'TRAINING FOR END'
                                    ,141536,'NEW REQUEST'
                                    ,141537,'NO REPAIR REQUIR'
                                    ,141538,'REPLACED PARTS'
                                    ,141539,'REPLACE EQUIPMEN'
                                    ,1000699,'NEW REQUEST',NULL,' ') AS REPAIR_DEFINITIONS
             ,JT.JT_REPAIRDESC AS REPAIR_DESCRIPTION
             ,JT.JT_REQUESTOR AS REQUESTOR
    --         ,' ' AS REQUESTOR_COST_CENTER
             ,JT.JT_REQUESTOR_EMAIL AS REQUESTOR_EMAIL
             ,JT.JT_REQUESTOR_NAME_FIRST AS REQUESTOR_NAME
             ,JT.JT_REQUESTOR_PHONE AS REQUESTOR_PHONE
    --         ,' ' AS RESPONSE_TIME
             ,RM.ROOM_NAME_CC AS ROOM
             ,P1.PEO_PROVIDER_CODE1 AS SERVICE_PROVIDER
             ,P1.PEO_ADDRESS_1 AS SERVICE_PROVIDER_ADDRESS
             ,PEOCITY.CITY_TEXT SERVICE_PROVIDER_CITY
             ,P1.PEO_PROVIDER_CODE1 AS SERVICE_PROVIDER_CODE
             ,PEOCITY.CITY_COUNTRY_NAME AS SERVICE_PROVIDER_COUNTRY
             ,PEOCUR.CURRENCY_TEXT AS SERVICE_PROVIDER_CURRENCY
             ,P1.PEO_NAME AS SERVICE_PROVIDER_DESCRIPTION
             ,P1.PEO_DISPATCH_METHOD AS SERV_PROV_DISPATC_HMETHOD
             ,P1.PEO_RATE_DOUBLE AS SERV_PROV_DOUBLE_TIME_RATE
             ,P1.PEO_EMAIL AS SERVICE_PROVIDER_EMAIL
             ,P1.PEO_EMERGENCY_PHONE AS SERV_PROV_EMERGENCY_PHONE
             ,P1.PEO_FAX AS SERVICE_PROVIDER_FAX_NUMBER
             ,P1.PEO_HOME_PHONE AS SERVICE_PROVIDER_HOME_PHONE
             ,P1.PEO_RATE_HOURLY AS SERVICE_PROVIDER_HOURLY_RATE
             ,P1.PEO_TITLE AS SERVICE_PROVIDER_JOB_TITLE
             ,P1.PEO_METHOD_ID AS SERVICE_PROVIDER_METHOD
             ,P1.PEO_CELL_PHONE AS SERVICE_PROVIDER_MOBILE_PHONE
             ,P1.PEO_PAGER AS SERVICE_PROVIDER_PAGER
             ,P1.PEO_RATE_DIFFERENTIAL AS SERVICE_PROVIDER_RATES
             ,P1.PEO_RATE_DIFFERENTIAL AS SER_PROV_SHIFT_DIFFERENTIAL
             ,PEOCITY.CITY_STATE_PROV_TEXT AS SERV_PROV_STATE_PROVINCE
             ,DECODE(P1.PEO_ACTIVE, 'Y', 'ACTIVE', 'INACTIVE') AS SERVICE_PROVIDER_STATUS
             ,P1.PEO_URL AS SERV_PROV_WEB_SITE_ADDRESS
             ,P1.PEO_PHONE AS SERVICE_PROVIDER_WORK_PHONE
             ,P1.PEO_POSTAL_CODE AS SERV_PROV_ZIP_POSTAL_CODE
    --         ,' ' AS SHIFT
    --         ,' ' AS SKILL
             ,DECODE(JT.JT_BIGSTATUS_ID,138813,'NEW'
                                       ,138814,'PENDING'
                                       ,138815,'OPEN'
                                       ,138816,'COMPLETED'
                                       ,138817,'CLOSED'
                                       ,138818,'CANCELLED',NULL,' ') AS STATUS
             ,LEV.LEVELS_NAME AS SUBREGION
    --         ,' ' AS TRADE
             ,P1.PEO_LS_INTERFACE_CODE1 AS VENDOR_ID
             ,P1.PEO_FAX AS VENDOR_PURCHASING_FAX
             ,P1.PEO_VENDOR_SITE_CODE AS VENDOR_SITECODE
             ,JT.JT_ID AS VENDOR_TICKET
             ,P1.PEO_NAME AS VENDOR_COMPANYNAME
             ,JT.JT_REQUESTOR_VIP AS VIP
             ,WO.WO_ID AS WORK_ORDER_NO
             ,JT.JT_ID AS WORK_REQUEST
             ,JT.JT_CLASS_ID AS WORK_REQUEST_CLASS
             ,WOTY.WORKTYPE_TEXT AS WORK_TYPE
    --         ,' ' AS WR_COST
             ,JT.JT_DESCRIPTION AS WR_DESCRIPTION
    --         ,' ' AS WR_DISPATCH_METHOD
             ,DECODE(JT.JT_BIGSTATUS_ID,138813,'NEW'
                                       ,138814,'PENDING'
                                       ,138815,'OPEN'
                                       ,138816,'COMPLETED'
                                       ,138817,'CLOSED'
                                       ,138818,'CANCELLED',NULL,' ') AS WR_STATUS
             ,CTRY.COUNTRY_NAME AS COUNTRY
             ,SYSDATE --LD_CURR_TIME
         FROM CITI.JOBTICKET JT,
              CITI.PROPERTY PROP,
              CITI.BLDG BL,
              CITI.BLDG_LEVELS BLDGLVL,
              CITI.LEVELS LEV,
              CITI.LEVELS PAR,
              (SELECT CRSTOOLS.STRAGG(PEO_NAME) FACILITY_MANAGER,
                      BLDGCON_BLDG_ID
                 FROM CITI.BLDG_CONTACTS, CITI.PEOPLE
                WHERE BLDGCON_PEO_ID = PEO_ID
                  AND BLDGCON_CONTYPE_ID IN (40181, 10142)
                GROUP BY BLDGCON_BLDG_ID) FMG,
              CITI.FLOORS FL,
              CITI.ROOM RM,
              CITI.GENERAL_LEDGER GL,
              CITI.LEGAL_ENTITY LE,
              CITI.COST_CENTER_CODES CC,
              CITI.EQUIPMENT EQP,
              CITI.WORKTYPE WOTY,
              CITI.SUBWORKTYPE SWOTY,
              CITI.WORK_ORDER WO,
              CITI.JT_WORKERS JTWO,
              CITI.PRIORITY,
              CITI.COUNTRY CTRY,
              CITI.PEOPLE P1,
              CITI.PEOPLE PEO3,
              CITI.PEOPLE PEO1,
              CITI.CITY PEOCITY,
              CITI.CURRENCY PEOCUR
        WHERE JT.JT_BLDG_ID = BL.BLDG_ID
          AND BL.BLDG_ID = BLDGLVL.BLDG_LEVELS_BLDG_ID
          AND BLDGLVL.BLDG_LEVELS_LEVELS_ID = LEV.LEVELS_ID
          AND LEV.LEVELS_PARENT = PAR.LEVELS_ID(+)
          AND PROP.PROPERTY_ID = BL.BLDG_PROPERTY_ID
          AND BL.BLDG_ACTIVE_LS = 'N'
          AND JT.JT_FLOORS_ID = FL.FLOORS_ID(+)
          AND JT.JT_ROOM_ID = RM.ROOM_ID(+)
          AND JT.JT_BLDG_ID = FMG.BLDGCON_BLDG_ID(+)
          AND JT.JT_GENLED_ID = GL.GENLED_ID(+)
          AND GL.GENLED_LGLENT_ID = LE.LGLENT_ID(+)
          AND JT.JT_CSTCTRCD_ID = CC.CSTCTRCD_ID(+)
          AND JT.JT_EQUIP_ID = EQP.EQUIP_ID(+)
          AND JT.JT_ID = JTWO.JTW_JT_ID(+)
          AND JT.JT_WORKTYPE_ID = WOTY.WORKTYPE_ID(+)
          AND JT.JT_SWORKTYPE_ID = SWOTY.SWORKTYPE_ID(+)
          AND JT.JT_WO_ID = WO.WO_ID
          AND JT.JT_PRIORITY_ID = PRIORITY_ID(+)
             --AND jt.jt_date_requested >= ADD_MONTHS (SYSDATE, -12)
          AND JT.JT_LAST_UPDATE >= ADD_MONTHS(LD_CURR_TIME, -12)
          AND BL.BLDG_COUNTRY_ID = CTRY.COUNTRY_ID
          AND JTWO.JTW_PEO_ID = P1.PEO_ID(+)
          AND P1.PEO_CITY_ID = PEOCITY.CITY_ID(+)
          AND JT.JT_COMPLETED_BY_PEO_ID = PEO3.PEO_ID(+)
          AND P1.PEO_RATE_CURRENCY_ID = PEOCUR.CURRENCY_ID(+)
          AND JT.JT_AGENT_PEO_ID = PEO1.PEO_ID(+)
       COMMIT;
    EXCEPTION
       WHEN OTHERS THEN
          ROLLBACK;
          DBMS_OUTPUT.PUT_LINE('SQLCODE :' || SQLCODE || ' Error :' || SQLERRM);
    END WORK_KIOSK_FULL;Here's the link for infor on the [Oracle Direct-Path INSERT |http://download.oracle.com/docs/cd/B10501_01/server.920/a96524/c21dlins.htm#10778].
    Also, if you are truly intent on using a CURSOR FOR LOOP with the BULK COLLECT, I suggest you read Steven Feuerstein's article [PL/SQL Practices: On BULK COLLECT |http://www.oracle.com/technology/oramag/oracle/08-mar/o28plsql.html].
    Hope this helps.
    Craig...
    If my response or the response of another was helpful, please mark it accordingly

  • Bulk Collect into is storing less no of rows in collection when using LIMIT?

    I have written the following anonymous PL SQL Block. However, the line dbms_output.put_line(total_tckt_col.LAST) gives me output as 366 (in DBMS_OUTPUT is SQL Developer) which is correct when no limit is set. If the limit is set to 100 in the FETCH statement then dbms_output.put_line(total_tckt_col.LAST) gives me 66. What I am doing wrong here?
    DECLARE
       CURSOR cur_total_tckt 
       is
       select  t.ticket_id ticket_id, t.created_date created_date, t.created_by created_by, t.ticket_status ticket_status,
      t.last_changed last_changed, h.created_date closed_date
       from n01.cc_ticket_info t
       inner join n01.cc_ticket_status_history h
       on (t.ticket_id = h.ticket_id)
       where t.last_changed >= '6/28/2012 17:28:59' and t.last_changed < (sysdate + interval '1' day);
      type total_tckt_colcn
       is
       TABLE OF cur_total_tckt%rowtype;
      total_tckt_col total_tckt_colcn;
      total_coach_col total_tckt_colcn;
       begin
      total_tckt_col  := total_tckt_colcn ();
      total_coach_col := total_tckt_colcn ();
       OPEN cur_total_tckt;
      loop
       fetch cur_total_tckt bulk collect into total_tckt_col;
    -- fetch cur_total_tckt bulk collect into total_tckt_col limit 100;
       EXIT
       WHEN (cur_total_tckt%NOTFOUND);
       END LOOP ;
       CLOSE cur_total_tckt;  
      dbms_output.put_line(total_tckt_col.LAST); 
       FOR i IN total_tckt_col.first..total_tckt_col.last
      LOOP
      dbms_output.put_line(i);
       END LOOP;
       end;

    Ishan wrote:
    Here is modified version of your code on standard EMP table in scott schema.
    Did you test it? All you demonstrate is last batch has 4 rows. But you print it outsite the loop. This way if last batch is incomplete (has less than limit rows) your loop doesn't process last batch. Assume you want to print enames:
    DECLARE
        CURSOR cur_total_tckt
          IS
            select  ename
              from  emp; -- I have a total of 14 records in this table
            type total_tckt_colcn
              is
                TABLE OF cur_total_tckt%rowtype;
            total_tckt_col total_tckt_colcn;
    BEGIN
        total_tckt_col  := total_tckt_colcn ();
        OPEN cur_total_tckt;
        LOOP
          fetch cur_total_tckt bulk collect into total_tckt_col limit 5;
          EXIT WHEN cur_total_tckt%NOTFOUND;
          FOR v_i IN 1..total_tckt_col.count LOOP
            dbms_output.put_line(total_tckt_col(v_i).ename);
          END LOOP;
        END LOOP ;
        CLOSE cur_total_tckt;
    END;
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    PL/SQL procedure successfully completed.
    SQL>
    As you can see, it didn't print last batch. Why? Because NOTFOUND is set to true if exact number of rows you asked to fetch was not fetched. So last batch has 4 rows while code asks to fetch 5. Therefore, NOTFOUND is set to true and code exits before processing that last batch. So you have to repeat processing code again outside the loop:
    DECLARE
        CURSOR cur_total_tckt
          IS
            select  ename
              from  emp; -- I have a total of 14 records in this table
            type total_tckt_colcn
              is
                TABLE OF cur_total_tckt%rowtype;
            total_tckt_col total_tckt_colcn;
    BEGIN
        total_tckt_col  := total_tckt_colcn ();
        OPEN cur_total_tckt;
        LOOP
          fetch cur_total_tckt bulk collect into total_tckt_col limit 5;
          EXIT WHEN cur_total_tckt%NOTFOUND;
          FOR v_i IN 1..total_tckt_col.count LOOP
            dbms_output.put_line(total_tckt_col(v_i).ename);
          END LOOP;
        END LOOP ;
        FOR v_i IN 1..total_tckt_col.count LOOP
          dbms_output.put_line(total_tckt_col(v_i).ename);
        END LOOP;
        CLOSE cur_total_tckt;
    END;
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    PL/SQL procedure successfully completed.
    SQL>
    But you must agree repeating that processing code twice isn't best solution. When using BULK COLLECT LIMIT we should exit not by NOTFOUND but rather by collection.count = 0:
    DECLARE
        CURSOR cur_total_tckt
          IS
            select  ename
              from  emp; -- I have a total of 14 records in this table
            type total_tckt_colcn
              is
                TABLE OF cur_total_tckt%rowtype;
            total_tckt_col total_tckt_colcn;
    BEGIN
        total_tckt_col  := total_tckt_colcn ();
        OPEN cur_total_tckt;
        LOOP
          fetch cur_total_tckt bulk collect into total_tckt_col limit 6;
          EXIT WHEN total_tckt_col.count = 0;
          FOR v_i IN 1..total_tckt_col.count LOOP
            dbms_output.put_line(total_tckt_col(v_i).ename);
          END LOOP;
        END LOOP ;
        CLOSE cur_total_tckt;
    END;
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    PL/SQL procedure successfully completed.
    SQL>
    SY.

  • How to use bulk collect into clause

    hi all,
    i have requirement like this i want to change the query by passing the different table names in oracle database 10gr2.
    like if i use first i pass the scott.emp table name select * from scott.emp;
    then i want pass scott.dept table name select * from scott.dept;
    using select * option in the select list.
    how can i execute it.
    give me any solution.
    please reply....

    Hi,
    i recently also ran into some serious trouble to make dynamic sql work.
    It was about parallel pipelined function with strongly typed cursor (for "partition ... by hash(...)").
    But in addition requiring dynamic SQL for the input to this cursor.
    I couldn't make it work with execute immediate or something else.
    So i used another way - I translated dynamic SQL into dynamically created static SQL:
    1. create a base SQL data object type with abstract interface for code (e.g. some Execute() member function).
    2. dynamically create a derived SQL data object type with concrete implementation of Execute() holding your "dynamic SQL" "in a static way"
    3. delegate to Execute().
    Let me quote my example from comp.databases.oracle.server, thread "dynamically created cursor doesn't work for parallel pipelined functions"
    - pls. see below (it's an old one - with likely some odd stuff inside).
    It might sound some kind of strange for DB programmer.
    (I come from C++. Though this is not an excuse smile)
    Maybe i just missed another possible option to handle the problem.
    And it's a definitely verbose.
    But i think it's at least a (last) option.
    Actually i would be interested to hear, what others think about it.
    best regards,
    Frank
    --------------- snip -------------------------
    drop table parallel_test;
    drop type MyDoit;
    drop type BaseDoit;
    drop type ton;
    create type ton as table of number;
    CREATE TABLE parallel_test (
    id NUMBER(10),
    description VARCHAR2(50)
    BEGIN
    FOR i IN 1 .. 100000 LOOP
    INSERT INTO parallel_test (id, description)
    VALUES (i, 'Description or ' || i);
    END LOOP;
    COMMIT;
    END;
    create or replace type BaseDoit as object (
    id number,
    static function make(p_id in number)
    return BaseDoit,
    member procedure doit(
    p_sids in out nocopy ton,
    p_counts in out nocopy ton)
    ) not final;
    create or replace type body BaseDoit as
    static function make(p_id in number)
    return BaseDoit
    is
    begin
    return new BaseDoit(p_id);
    end;
    member procedure doit(
    p_sids in out nocopy ton,
    p_counts in out nocopy ton)
    is
    begin
    dbms_output.put_line('BaseDoit.doit(' || id || ') invoked...');
    end;
    end;
    -- Define a strongly typed REF CURSOR type.
    CREATE OR REPLACE PACKAGE parallel_ptf_api AS
    TYPE t_parallel_test_row IS RECORD (
    id1 NUMBER(10),
    desc1 VARCHAR2(50),
    id2 NUMBER(10),
    desc2 VARCHAR2(50),
    sid NUMBER
    TYPE t_parallel_test_tab IS TABLE OF t_parallel_test_row;
    TYPE t_parallel_test_ref_cursor IS REF CURSOR RETURN
    t_parallel_test_row;
    FUNCTION test_ptf (p_cursor IN t_parallel_test_ref_cursor)
    RETURN t_parallel_test_tab PIPELINED
    PARALLEL_ENABLE(PARTITION p_cursor BY any);
    END parallel_ptf_api;
    SHOW ERRORS
    CREATE OR REPLACE PACKAGE BODY parallel_ptf_api AS
    FUNCTION test_ptf (p_cursor IN t_parallel_test_ref_cursor)
    RETURN t_parallel_test_tab PIPELINED
    PARALLEL_ENABLE(PARTITION p_cursor BY any)
    IS
    l_row t_parallel_test_row;
    BEGIN
    LOOP
    FETCH p_cursor
    INTO l_row;
    EXIT WHEN p_cursor%NOTFOUND;
    select userenv('SID') into l_row.sid from dual;
    PIPE ROW (l_row);
    END LOOP;
    RETURN;
    END test_ptf;
    END parallel_ptf_api;
    SHOW ERRORS
    PROMPT
    PROMPT Serial Execution
    PROMPT ================
    SELECT sid, count(*)
    FROM TABLE(parallel_ptf_api.test_ptf(CURSOR(SELECT t1.id,
    t1.description, t2.id, t2.description, null
    FROM parallel_test t1,
    parallel_test t2
    where t1.id = t2.id
    ) t2
    GROUP BY sid;
    PROMPT
    PROMPT Parallel Execution
    PROMPT ==================
    SELECT sid, count(*)
    FROM TABLE(parallel_ptf_api.test_ptf(CURSOR(SELECT /*+
    parallel(t1,5) */ t1.id, t1.description, t2.id, t2.description, null
    FROM parallel_test t1,
    parallel_test t2
    where t1.id = t2.id
    ) t2
    GROUP BY sid;
    PROMPT
    PROMPT Parallel Execution 2
    PROMPT ==================
    set serveroutput on;
    declare
    v_sids ton := ton();
    v_counts ton := ton();
    -- v_cur parallel_ptf_api.t_parallel_test_ref_cursor;
    v_cur sys_refcursor;
    procedure OpenCursor(p_refCursor out sys_refcursor)
    is
    begin
    open p_refCursor for 'SELECT /*+ parallel(t1,5) */ t1.id,
    t1.description, t2.id, t2.description, null
    FROM parallel_test t1,
    parallel_test t2
    where t1.id = t2.id';
    end;
    begin
    OpenCursor(v_cur);
    SELECT sid, count(*) bulk collect into v_sids, v_counts
    FROM TABLE(parallel_ptf_api.test_ptf(v_cur)) t2
    GROUP BY sid;
    for i in v_sids.FIRST.. v_sids.LAST loop
    dbms_output.put_line (v_sids(i) || ', ' || v_counts(i));
    end loop;
    end;
    PROMPT
    PROMPT Parallel Execution 3
    PROMPT ==================
    set serveroutput on;
    declare
    instance BaseDoit;
    v_sids ton := ton();
    v_counts ton := ton();
    procedure CreateMyDoit
    is
    cmd varchar2(4096 char);
    begin
    cmd := 'create or replace type MyDoit under BaseDoit ( ' ||
    ' static function make(p_id in number) ' ||
    ' return MyDoit, ' ||
    ' overriding member procedure doit( ' ||
    ' p_sids in out nocopy ton, ' ||
    ' p_counts in out nocopy ton) ' ||
    execute immediate cmd;
    cmd := 'create or replace type body MyDoit as ' ||
    ' static function make(p_id in number) ' ||
    ' return MyDoit ' ||
    ' is ' ||
    ' begin ' ||
    ' return new MyDoit(p_id); ' ||
    ' end; ' ||
    ' ' ||
    ' overriding member procedure doit( ' ||
    ' p_sids in out nocopy ton, ' ||
    ' p_counts in out nocopy ton) ' ||
    ' is ' ||
    ' begin ' ||
    ' dbms_output.put_line(''MyDoit.doit('' || id || '')
    invoked...''); ' ||
    ' SELECT sid, count(*) bulk collect into p_sids, p_counts ' ||
    ' FROM TABLE(parallel_ptf_api.test_ptf(CURSOR( ' ||
    ' SELECT /*+ parallel(t1,5) */ t1.id, t1.description,
    t2.id, t2.description, null ' ||
    ' FROM parallel_test t1, parallel_test t2 ' ||
    ' where t1.id = t2.id ' ||
    ' ))) ' ||
    ' GROUP BY sid; ' ||
    ' end; ' ||
    ' end; ';
    execute immediate cmd;
    end;
    begin
    CreateMyDoit;
    execute immediate 'select MyDoit.Make(11) from dual' into instance;
    instance.doit(v_sids, v_counts);
    if v_sids.COUNT > 0 then
    for i in v_sids.FIRST.. v_sids.LAST loop
    dbms_output.put_line (v_sids(i) || ', ' || v_counts(i));
    end loop;
    end if;
    end;
    --------------- snap -------------------------

  • BULK COLLECT INTO (Oracle 11 G)

    ORACLE 11G (The same code works fine in Oracle 9i)
    FETCH v_cursor BULK COLLECT INTO AuditData, AuditData1;
    the above statement gives me an error:-
    ORA-01007: variable not in select list
    ORA-06512: at "DEC0512.FCT_AUD_TRAIL_REAL_ENTRY_UPD", line 175
    ORA-06512: at line 1
    But if the change the statemement to
    FETCH v_cursor BULK COLLECT INTO AuditData;
    The query works fine.
    Any help will be much appreciated.

    >
    ORACLE 11G (The same code works fine in Oracle 9i)
    FETCH v_cursor BULK COLLECT INTO AuditData, AuditData1;
    the above statement gives me an error:-
    ORA-01007: variable not in select list
    ORA-06512: at "DEC0512.FCT_AUD_TRAIL_REAL_ENTRY_UPD", line 175
    ORA-06512: at line 1
    But if the change the statemement to
    FETCH v_cursor BULK COLLECT INTO AuditData;
    The query works fine.
    Any help will be much appreciated.
    >
    If the second query 'works fine' then your 'AuditData' collection is consuming all of the result set columns and there is nothing to put into the other collection.
    So you have a mismatch between the result set your cursor returns and those collections you are trying to put the data into.
    This works for me:
    DECLARE
      CURSOR c1 IS (SELECT empno, deptno FROM emp);
      empno_tab dbms_sql.number_table;
      deptno_tab dbms_sql.number_table;
    BEGIN
      OPEN c1;
      LOOP                                                 --Loop added
        FETCH c1 BULK COLLECT INTO empno_tab, deptno_tab LIMIT 3; -- process 3 records at a time
            -- process the first 3 records
           DBMS_OUTPUT.PUT_LINE('Processing ' || empno_tab.COUNT || ' records.');
            FOR i in 1..empno_tab.count loop
                dbms_output.put_line('empno is [' || empno_tab(i) || '].');
            end loop;
        EXIT WHEN c1%NOTFOUND;
      END LOOP;
      DBMS_OUTPUT.PUT_LINE('All done');
    END;
    Processing 3 records.
    empno is [7369].
    empno is [7499].
    empno is [7521].
    Processing 3 records.
    empno is [7566].
    empno is [7654].
    empno is [7698].
    Processing 3 records.
    empno is [7782].
    empno is [7788].
    empno is [7839].
    Processing 3 records.
    empno is [7844].
    empno is [7876].
    empno is [7900].
    Processing 2 records.
    empno is [7902].
    empno is [7934].
    All done

  • Please help with the query (INSERT RETURNING BULK COLLECT INTO)

    I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
    Here is a full query that use in the C# code
    INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, BENEFICIARY_FIRST_NAME,
    BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE,
    LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL,
    ATTENDING_PROVIDER_NUMBER, BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI)
    VALUES
    (SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs,
    :REQUEST_METHOD_IDs, :SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs,
    :SERVICE_LOCATION_STATEs, :BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs,
    :HICNUMs, :CCNs, :CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs,
    :CONTRACTOR_IDs, :PRIORITY_IDs, :UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs,
    :ATTENDING_PROVIDER_NUMBERs, :BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs,
    :STUDY_IDs, :REFERRING_NPIs) RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs
    However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
    Please help me resolve this error or I would appreciate a different solution
    Thank you

    You cannot use (and do not want to in this case) the BULK COLLECT.
    create table for_testing
       the_id      number not null primary key,
       some_data   number
    declare
       l_return_value for_testing.the_id%type;
    begin
      4 
       insert into for_testing
          the_id,
          some_data
       values
          1,
          5
       returning the_id into l_return_value;
       dbms_output.put_line('the return values is ' || l_return_value);
    end;
    20  /
    the return values is 1
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.02
    TUBBY_TUBBZ?Is a simple example. In the future, please use the tags to preserve formatting on your code like i have so it remains readable .                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for