Need help in Bulk collect

Hi All,
I need a help to create a bulk statement. Please find the scenario below
I would like to copy a table A from table B using bulk collect also the table A has more records (1Million). Before doing this I need to either truncate the table B or drop the table to load the data from table A.
Please provide me the correct statement to achieve this request. Thanks in advance!!
Regards,
Boovan.

disabling any indexes on the target should be looked at first. If there are none then look at the above.
When you do a direct path load the indexes are build after loading.The point is that the direct path load does not avoid the undo due to the indexes.
In this example on a table with no indexes the undo used goes from 216kb to 16kb using append.
When an index is added the undo used goes up from 216kb to 704kb an increase of 488kb for a standard insert.
For the direct path insert the undo goes up from 16kb to 440kb so almost the full amount of undo due to the index.
So the presence of a single index can have a much greater impact on the amount of undo required than the use of a direct path load and that undo may not be avoided by the use of a direct path load unless the index is disabled beforehand.
Also note the tiny amounts of undo we are talking about for 50k rows.
SQL> create table t as select * from all_objects where 0 = 1;
Table created.
SQL> insert into t select * from all_objects;
56108 rows created.
SQL> select
  2      used_ublk undo_used_blk,
  3      used_ublk * blk_size_kb undo_used_kb,
  4      log_io logical_io,
  5      cr_get consistent_gets
  6  from
  7      v$transaction, v$session s,
  8      (select distinct sid from v$mystat) m,
  9      (select to_number(value)/1024 blk_size_kb
10          from v$parameter where name='db_block_size')
11  where
12      m.sid       =   s.sid
13  and ses_addr    =   saddr;
UNDO_USED_BLK UNDO_USED_KB LOGICAL_IO CONSISTENT_GETS
           27          216      13893         1042736
SQL> rollback;
Rollback complete.
SQL> insert /*+ append */ into t select * from all_objects;
56108 rows created.
SQL> select
  2      used_ublk undo_used_blk,
  3      used_ublk * blk_size_kb undo_used_kb,
  4      log_io logical_io,
  5      cr_get consistent_gets
  6  from
  7      v$transaction, v$session s,
  8      (select distinct sid from v$mystat) m,
  9      (select to_number(value)/1024 blk_size_kb
10          from v$parameter where name='db_block_size')
11  where
12      m.sid       =   s.sid
13  and ses_addr    =   saddr;
UNDO_USED_BLK UNDO_USED_KB LOGICAL_IO CONSISTENT_GETS
            2           16       1307         1041151
SQL> rollback;
Rollback complete.
SQL> create unique index t_idx on t (object_id);
Index created.
SQL> insert into t select * from all_objects;
56109 rows created.
SQL> select
  2      used_ublk undo_used_blk,
  3      used_ublk * blk_size_kb undo_used_kb,
  4      log_io logical_io,
  5      cr_get consistent_gets
  6  from
  7      v$transaction, v$session s,
  8      (select distinct sid from v$mystat) m,
  9      (select to_number(value)/1024 blk_size_kb
10          from v$parameter where name='db_block_size')
11  where
12      m.sid       =   s.sid
13  and ses_addr    =   saddr;
UNDO_USED_BLK UNDO_USED_KB LOGICAL_IO CONSISTENT_GETS
           88          704      20908         1043193
SQL> rollback;
Rollback complete.
SQL> insert /*+ append */ into t select * from all_objects;
56109 rows created.
SQL> select
  2      used_ublk undo_used_blk,
  3      used_ublk * blk_size_kb undo_used_kb,
  4      log_io logical_io,
  5      cr_get consistent_gets
  6  from
  7      v$transaction, v$session s,
  8      (select distinct sid from v$mystat) m,
  9      (select to_number(value)/1024 blk_size_kb
10          from v$parameter where name='db_block_size')
11  where
12      m.sid       =   s.sid
13  and ses_addr    =   saddr;
UNDO_USED_BLK UNDO_USED_KB LOGICAL_IO CONSISTENT_GETS
           57          456       2310         1041047

Similar Messages

  • Need help with Bulk Collect ForAll Update

    Hi - I'm trying to do a Bulk Collect/ForAll Update but am having issues.
    My declarations look like this:
         CURSOR cur_hhlds_for_update is
            SELECT hsh.household_id, hsh.special_handling_type_id
              FROM compas.household_special_handling hsh
                 , scr_id_lookup s
             WHERE hsh.household_id = s.id
               AND s.scr = v_scr
               AND s.run_date = TRUNC (SYSDATE)
               AND effective_date IS NULL
               AND special_handling_type_id = 1
               AND created_by != v_user;
         TYPE rec_hhlds_for_update IS RECORD (
              household_id  HOUSEHOLD_SPECIAL_HANDLING.household_id%type,
              spec_handl_type_id HOUSEHOLD_SPECIAL_HANDLING.SPECIAL_HANDLING_TYPE_ID%type
         TYPE spec_handling_update_array IS TABLE OF rec_hhlds_for_update;
         l_spec_handling_update_array  spec_handling_update_array;And then the Bulk Collect/ForAll looks like this:
           OPEN cur_hhlds_for_update;
           LOOP
            FETCH cur_hhlds_for_update BULK COLLECT INTO l_spec_handling_update_array LIMIT 1000;
            EXIT WHEN l_spec_handling_update_array.count = 0;
            FORALL i IN 1..l_spec_handling_update_array.COUNT
            UPDATE compas.household_special_handling
               SET effective_date =  TRUNC(SYSDATE)
                 , last_modified_by = v_user
                 , last_modified_date = SYSDATE
             WHERE household_id = l_spec_handling_update_array(i).household_id
               AND special_handling_type_id = l_spec_handling_update_array(i).spec_handl_type_id;
              l_special_handling_update_cnt := l_special_handling_update_cnt + SQL%ROWCOUNT;         
          END LOOP;And this is the error I'm receiving:
    ORA-06550: line 262, column 31:
    PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
    ORA-06550: line 262, column 31:
    PLS-00382: expression is of wrong type
    ORA-06550: line 263, column 43:
    PL/SQL: ORA-22806: not an object or REF
    ORA-06550: line 258, column 9:
    PL/SQL: SQMy problem is that the table being updated has a composite primary key so I have two conditions in my where clause. This the the first time I'm even attempting the Bulk Collect/ForAll Update and it seems like it would be straight forward if I was only dealing with a single-column primary key. Can anyone please help advise me as to what I'm missing here or how I can accomplish this?
    Thanks!
    Christine

    You cannot reference a column inside a record when doin a for all. You need to refer as a whole collection . So you will need two collections.
    Try like this,
    DECLARE
       CURSOR cur_hhlds_for_update
       IS
          SELECT hsh.household_id, hsh.special_handling_type_id
            FROM compas.household_special_handling hsh, scr_id_lookup s
           WHERE hsh.household_id = s.ID
             AND s.scr = v_scr
             AND s.run_date = TRUNC (SYSDATE)
             AND effective_date IS NULL
             AND special_handling_type_id = 1
             AND created_by != v_user;
       TYPE arr_household_id IS TABLE OF HOUSEHOLD_SPECIAL_HANDLING.household_id%TYPE
                                   INDEX BY BINARY_INTEGER;
       TYPE arr_spec_handl_type_id IS TABLE OF HOUSEHOLD_SPECIAL_HANDLING.SPECIAL_HANDLING_TYPE_ID%TYPE
                                         INDEX BY BINARY_INTEGER;
       l_household_id_col         arr_household_id;
       l_spec_handl_type_id_col   arr_spec_handl_type_id;
    BEGIN
       OPEN cur_hhlds_for_update;
       LOOP
          FETCH cur_hhlds_for_update
            BULK COLLECT INTO l_household_id_col, l_spec_handl_type_id_col
          LIMIT 1000;
          EXIT WHEN cur_hhlds_for_update%NOTFOUND;
          FORALL i IN l_household_id_col.FIRST .. l_household_id_col.LAST
             UPDATE compas.household_special_handling
                SET effective_date = TRUNC (SYSDATE),
                    last_modified_by = v_user,
                    last_modified_date = SYSDATE
              WHERE household_id = l_household_id_col(i)
                AND special_handling_type_id = l_spec_handl_type_id_col(i);
       --l_special_handling_update_cnt := l_special_handling_update_cnt + SQL%ROWCOUNT; -- Not sure what this does.
       END LOOP;
    END;G.

  • Needed help in bulk collect using collections

    Hi,
    I have created a schema level collection like "CREATE OR REPLACE TYPE T_EMP_NO IS TABLE OF NUMBER ;
    will i able to use this in a where clause which involves bulk collect?
    Please share ur thoughts.
    My oracle version is 10g

    user13710379 wrote:
    Will i be able to do a bulk collect into a table using this collection of my sql type?Bulk fetches collects into an array like structure - not into a SQL table like structure. So calling a collection variable in PL/SQL a "+PL/SQL table+" does not make much sense as this array structure is nothing like a table. For the same reason, one needs to question running SQL select statements against PL/SQL arrays.
    As for your SQL type defined - it is a collection (array) of numbers. Thus it can be used to bulk fetch a numeric column.

  • I need help on bulk inserts....

    Hello,
    I need help on bulk inserts. I have heard about it but don't know how to do it and how to specify the number of records to be inserted at a time.
    Can anyone please help me out?
    For example: I would like to insert in my TEST_TABLE a group of data at tha same time...
    INSERT INTO TEST_TABLE VALUES ( (1, 'xxx', 'www'), (2, 'yyy', 'hhh'), (3, 'aaa', 'kkk') )
    I using Oracle 10g .
    Tks!!
    Message was edited by:
    user532944
    Message was edited by:
    user532944

    But I want to insert a group of data at the same time, with one sql instruction...
    I don´t know if exists this SQL command...I just know that I can insert
    string sqlStmt = "INSERT INTO TESTE VALUES (:x, :x, :x)";
    stmt = con->createStatement (sqlStmt);
    But and this instruction ?? In MYSql I can do it!!
    string sqlStmt = "INSERT INTO TESTE VALUES ((:x, :x, :x), (:x, :x, :x));
    Message was edited by:
    user532944

  • I need an help regarding Bulk collect

    Can we use bulkcollect with sys_refursor ?
    for ex :
    create or replace procedure sampelpro ( recs out sys_refcursor) is
    begin
    execute immediate 'select * from table1' bulk collect into recs ;
    end sampelpro;
    Note : table1 has 1+ laks record
    if the above code is not possible then let me know any possible ways ?

    Hi and welcome to the forum
    Can we use bulkcollect with sys_refursor ?No, and you shouldn't.
    Your signature says that OUT parameter is a cursor. A cursor is not a resultset, but rather a pointer to one.
    So your best choice is probably just to use that, and not try to select into a collection.
    Note : table1 has 1+ laks recordEven more important then not to return a collection, but a cursor. (Although I don't remember what a lak is)
    Example on how to use:
    create or replace procedure sampelpro (recs out sys_refcursor)
    is
    begin
        open recs for 'select empno, ename from emp';
    end sampelpro;
    Procedure er oprettetAnd a test. Imagine this being a Java client or something the like
    SQL> var c refcursor
    SQL> exec sampelpro(:c)
    PL/SQL-procedure er udf°rt.
    SQL> print c
         EMPNO ENAME
          7369 SMITH
          7499 ALLEN
          7521 WARD
          7566 JONES
          7654 MARTIN
          7698 BLAKE
          7782 CLARK
          7788 SCOTT
          7839 KING
          7844 TURNER
          7876 ADAMS
         EMPNO ENAME
          7900 JAMES
          7902 FORD
          7934 MILLER
    14 rµkker er valgt.
    SQL>Blushadow has a nice post on cursors here:
    PL/SQL 101 : Understanding Ref Cursors
    Regards
    Peter

  • Help in BULK COLLECT

    In emp table having 14 records when i use the BULK COLLECT its inserting the 12 records only
    with out limting its working fine But when u limit the records inserting the 12 records only
    i need 14 records to be inserted in emps table through limiting ..
    Suggest me in this
    DECLARE
      TYPE a_recs IS TABLE OF emps%ROWTYPE;
      v_recs a_recs;
      CURSOR c1 IS
      SELECT *
      FROM emp;
    BEGIN
      DELETE FROM emps;
      COMMIT;
      OPEN c1;
      LOOP
         FETCH c1 BULK COLLECT INTO v_recs LIMIT 3;
         EXIT WHEN c1%NOTFOUND;
          FORALL i IN v_recs.FIRST..v_recs.LAST
          INSERT INTO emps
            VALUES v_recs(i);
      END LOOP;
      CLOSE c1;
    END;Thanks

    assuming this is only an exercise, change the order of FORALL and EXIT
    FORALL i IN v_recs.FIRST..v_recs.LAST
    INSERT INTO emps
    VALUES v_recs(i);
    EXIT WHEN c1%NOTFOUND;otherwise, just do
    insert into emps
    select *
      from empEdited by: Alex Nuijten on Aug 5, 2009 8:50 AM

  • Need help moving music collection from external hard drive to Macbook Pro

         I just bought a Macbook Pro today after my Windows desktop was bricked a few weeks ago. Luckily, I didn't lose the most important files on my pc, my music, because it was all on my Zune, as well. So, I borrowed an external hard drive, copied all of the music from my zune onto a friend's pc, and then copied it again from their pc to the external. Finally, I just plugged the external into my new mac, copied the folder within it holding my music, and hit "paste item" in the "Automatically Add to iTunes" folder. Initially, everything seemed to work perfectly, however, after transferring a little over 7 of my 54gb of music, an error message appeared saying that the operation was ending because it could not transfer all files.
         I then tried playing a file off of the hard drive, a wma, and received a prompt that the file was incompatible with Quicktime player, the default for no apparent reason. I tried then opening it with iTunes, and nothing happened, as far as I could see. Naturally, my next step was to google how one would transfer wma files to a mac, and, to make matters even more confusing, all of the results seemed to tell me that iTunes should automatically convert wma files to mp3, which does not seem to be happening in my case.
         I'm still not sure why this isn't working, as I'm sure more than 7gb of my music collection is non-wma, so that doesn't even seem to be the sole issue. Any help with importing my collection would be hugely appreciated, as I'm enjoying my mac so far, but will have to return it if I can't get music on here.
         Thanks.

    One problem is that iTunes for Mac can't handle WMA files, iTunes for Windows will convert them, but not iTunes for Mac. When you add unprotected WMA files to your iTunes library (Windows only), iTunes converts them to new files that iTunes can play, based on your import settings. See if you can use your friend's PC to do this.  If the borrowed PC has iTunes, create an alternate iTunes library so you don't mess up your friend's library.  This explains how:  http://support.apple.com/kb/HT1589
    This support document might be helpful:  iTunes: About the Add to Library, Import, and Convert functions, http://support.apple.com/kb/ht1347

  • Need Help With Smart Collections (Lightroom 2.7)

    I am trying to set up a smart collection to list files that are blank in the Location field.  Some fields such as Caption allow you to check if the field "is empty".  Location does not allow the "is empty" option.  What can I do to check if Location is empty or blank?

    Does not contain a e i o u.
    Yes, it's stupid that you need such workarounds.

  • Need help with APEX Collection - C

    Hi
    I have values in 2 fields on my page that I use to build a collection - "On Submit - After Computations and Validations"
    I want to delete collection using HTMLDB_COLLECTION.DELETE_COLLECTION ; and recreate if user changes a value in any of the above 2 fileds ( field 1 is LOV and field 2 is DATE )
    I know I have to use AJAX but could not figure out how to code it . Can someone please direct me to any similar peice of code or suggest the steps?
    Thanks
    Aali

    You can find it here:
    http://apex.oracle.com/pls/otn/f?p=31517:246
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

  • Need help serialize a collection object

    I have a class that's going to manage a list of paths stored as strings as "ArrayList<String> fileList = null;". I can't figure out how to serialize the fileList object. The class that contains the fileList implements Externalizable. here are the read and write functions:
         public void readExternal(ObjectInput in) throws IOException
              fileList = (ArrayList)in.readObject();
         public void writeExternal(ObjectOutput out)  throws IOException//, ClassNotFoundException
              out.writeObject(fileList);
         }I've tried lots of different things and nothing works. Anybody know how to serialize an ArrayList? Is ArrayList the best class for the job?

    I have a class that's going to manage a list of paths
    stored as strings as "ArrayList<String> fileList =
    null;". I can't figure out how to serialize the
    fileList object. You don't have to do anything to serialize ArrayList, it is already Serializable.
    The class that contains the fileList
    implements Externalizable. here are the read and
    write functions:I will assume there is a good reason this class (that contains the fileList) can itself not be Serializable and needs to be Externelizable.
    >
    public void readExternal(ObjectInput in) throws
    s IOException
              fileList = (ArrayList)in.readObject();
    public void writeExternal(ObjectOutput out)  throws
    s IOException//, ClassNotFoundException
              out.writeObject(fileList);
         }I've tried lots of different things and nothing
    works. Anybody know how to serialize an ArrayList? Is
    ArrayList the best class for the job?I tried the same example -- with code to make it compilable and testable -- and it works as expected.
    What exactly do you mean when you say "nothing works"?

  • Need help deleting bulk e-mail

    How do I delete 21,000 messages easily and quickly. Only options seems to be 30 at a time......

    I point to
    http://forums.verizon.com/t5/Verizon-net-Email/How​-to-delete-thousands-of-emails/m-p/475355#M9196
    and I quote from it.
    1. Click on Settings
    2. Change Number of messages per page  to "no limit"
    3. Click on "save" below display tab and Click on "OK" on the pop up
    That is the secret my friends
    The next time you are in your inbox and Click on the select all rows button (below delete button) and it will select all of the inbox
    Click on "delete" button and it is DONE!
    If you are the original poster (OP) and your issue is solved, please remember to click the "Solution?" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the "Kudos" button.

  • Help needed in bulk collect

    Hi,
    below procedure is throwing error like "invalid sql". i doubt problem is with insert statement inside the body of the procedure, please help me how to load table with individual columns in bulk collect
    CREATE OR REPLACE PROCEDURE subscriber_load
    IS
    TYPE r_subscriber_data IS RECORD
    ( acct_no      LPDADMIN.SUBSCRIBER.acct_no%TYPE,
         acct_status_cd           LPDADMIN.SUBSCRIBER.acct_status_cd%TYPE,
              connect_date                LPDADMIN.SUBSCRIBER.connect_date%TYPE,
              disconnect_date           LPDADMIN.SUBSCRIBER.disconnect_date%TYPE,
              bill_salutation_cd           LPDADMIN.SUBSCRIBER.bill_salutation_cd%TYPE,
              bill_first_name           LPDADMIN.SUBSCRIBER.bill_first_name%TYPE,
              bill_last_name                LPDADMIN.SUBSCRIBER.bill_last_name%TYPE,
              bill_addr_1                LPDADMIN.SUBSCRIBER.bill_addr_1%TYPE,
              bill_addr_2                LPDADMIN.SUBSCRIBER.bill_addr_2%TYPE,
              bill_city                     LPDADMIN.SUBSCRIBER.bill_city%TYPE,
              bill_postal_code           LPDADMIN.SUBSCRIBER.bill_postal_code%TYPE,
              bill_province_cd           LPDADMIN.SUBSCRIBER.bill_province_cd%TYPE,
              bill_cycle_day                LPDADMIN.SUBSCRIBER.bill_cycle_day%TYPE,
              home_phone                     LPDADMIN.SUBSCRIBER.home_phone%TYPE,
    business_phone                LPDADMIN.SUBSCRIBER.business_phone%TYPE,
    first_name                     LPDADMIN.SUBSCRIBER.first_name%TYPE,
    last_name                     LPDADMIN.SUBSCRIBER.last_name%TYPE,
    home_phone                     LPDADMIN.SUBSCRIBER.home_phone%TYPE,
    delql_status_cd           LPDADMIN.SUBSCRIBER.delql_status_cd%TYPE,
    service_address_1           LPDADMIN.SUBSCRIBER.service_address_1%TYPE,
    service_address_2           LPDADMIN.SUBSCRIBER.service_address_2%TYPE,
    service_city                LPDADMIN.SUBSCRIBER.service_city%TYPE,
    service_province_cd      LPDADMIN.SUBSCRIBER.service_province_cd%TYPE
    TYPE t_subscriber_data IS TABLE OF r_subscriber_data INDEX BY BINARY_INTEGER;
    table_subscriber_data t_subscriber_data;
    CURSOR c_subscriber_data IS
    SELECT s.acct_no
    ,lb.lob_status_cd
    ,s.connect_date
    ,s.disconnect_date
    ,s.bill_to_salutation_cd
    ,substr(s.bill_to_name,instr(bill_to_name,',',1)+1) bill_first_name
    ,substr(s.bill_to_name,1,instr(bill_to_name,',',1)-1) bill_last_name
    ,s.bill_to_addr_1
    ,s.bill_to_addr_2
    ,s.bill_to_city
    ,s.bill_to_postal_code
    ,s.bill_to_province_cd
    ,s.bill_create_day_of_month
    ,s.home_phone
    ,s.business_phone
    ,substr(s.name,instr(bill_to_name,',',1)+1) first_name
    ,substr(s.name,1,instr(bill_to_name,',',1)-1) last_name
    ,s.home_phone
    ,s.delq_status_cd
    ,h.addr_1
    ,h.addr_2
    ,h.city
    ,h.province_cd
    FROM ccsadmin.subscriber s
    inner join CCSADMIN.HOUSE h
    on s.HOUSE_KEY = h.HOUSE_NO
    left outer join CCSADMIN.LINE_OF_BUSINESS lb
    on h.HOUSE_NO = lb.HOUSE_NO
    WHERE lb.LOB_TYPE_CD ='C'
    AND lb.HOUSE_NO IS NOT NULL;
    BEGIN
    OPEN c_subscriber_data;
    LOOP
    FETCH c_subscriber_data BULK COLLECT INTO table_subscriber_data LIMIT 100000;
    EXIT WHEN table_subscriber_data.COUNT = 0;
    if table_subscriber_data.COUNT>0 then
    FOR idx IN table_subscriber_data.first..table_subscriber_data.last loop
    INSERT INTO LPDADMIN.SUBSCRIBER(acct_no
                                                      ,acct_status_cd
                                                      ,connect_date
                                                      ,disconnect_date
                                                      ,bill_salutation_cd
                                                      ,bill_first_name
                                                      ,bill_last_name
                                                      ,bill_addr_1
                                                      ,bill_addr_2
                                                      ,bill_city
                                                      ,bill_postal_code
                                                      ,bill_province_cd
                                                      ,bill_cycle_day
                                                      ,home_phone
                                            ,business_phone
                                                      ,first_name
                                                      ,last_name
                                                      ,home_phone
                                                      ,delql_status_cd
                                                      ,service_address_1
                                                      ,service_address_2
                                                      ,service_city
                                                      ,service_province_cd
         VALUES (table_subscriber_data(idx).acct_no
         ,table_subscriber_data(idx).acct_status_cd
         ,table_subscriber_data(idx).connect_date
                   ,table_subscriber_data(idx).disconnect_date      
                   ,table_subscriber_data(idx).bill_salutation_cd
                   ,table_subscriber_data(idx).bill_first_name      
                   ,table_subscriber_data(idx).bill_last_name      
                   ,table_subscriber_data(idx).bill_addr_1           
                   ,table_subscriber_data(idx).bill_addr_2           
                   ,table_subscriber_data(idx).bill_city           
                   ,table_subscriber_data(idx).bill_postal_code
                   ,table_subscriber_data(idx).bill_province_cd
                   ,table_subscriber_data(idx).bill_cycle_day      
                   ,table_subscriber_data(idx).home_phone           
         ,table_subscriber_data(idx).business_phone      
         ,table_subscriber_data(idx).first_name           
         ,table_subscriber_data(idx).last_name           
         ,table_subscriber_data(idx).home_phone           
         ,table_subscriber_data(idx).delql_status_cd      
         ,table_subscriber_data(idx).service_address_1
         ,table_subscriber_data(idx).service_address_2
         ,table_subscriber_data(idx).service_city      
         ,table_subscriber_data(idx).service_province_cd);
    END LOOP;
    end if;
    END subscriber_load;
    /

    no PL/SQL required
    INSERT INTO LPDADMIN.SUBSCRIBER(acct_no
    ,acct_status_cd
    ,connect_date
    ,disconnect_date
    ,bill_salutation_cd
    ,bill_first_name
    ,bill_last_name
    ,bill_addr_1
    ,bill_addr_2
    ,bill_city
    ,bill_postal_code
    ,bill_province_cd
    ,bill_cycle_day
    ,home_phone
    ,business_phone
    ,first_name
    ,last_name
    ,home_phone
    ,delql_status_cd
    ,service_address_1
    ,service_address_2
    ,service_city
    ,service_province_cd
    ) SELECT .....

  • 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();
        }

  • Please help me on "Bulk Collect"

    Hi All,
    I've a query like :
    select deptno,
    min(sal)
    from emp;
    The above query is taking some 1.2 min to return the expected result of 91k rows and taking cost of 3666.
    But when i re written the query like;
    select deptno,
    min(sal)
    from emp where deptno = :dno;
    It is giving the correct result & taking very less time,but i need to get the result for all dept's without passing the deptno dynamically.
    As per my knowledge i planing to create one function using "Bulk-Collect" and return the all deptno.That result i 've to use in where condition.
    But when i trying to create a function i'm not able to do it.. SO can anyone help how to solve the above problem..
    How to pass the entire column values in where condition using function..
    Do i need to create a function or is there any other way of doing it..
    Please help me...
    Thanks,
    gra

    Hi,
    I don't follow you when you say that want to get all departments and them pass them back to your query, that makes no sense to me.
    If you want max salary for all departments, just:
    select deptno, min(sal) min_sal
      from emp
    group by deptno;No function, no bulk collect no nothing, but plain SQL.
    Regards
    Peter

  • Help need  for  PL/SQL  collections

    Hi All,
    Please help me to solve the following Error.
    Error # ORA-06533: Subscript beyond count.
    I am using Oracle 10g.
    I have data in the Test_table
    id_col stat_col reason_col
    101 A          HPQ
    101 A NULL
    101 NULL EDU
    101 P NULL
    102 P NULL
    102 NULL HEN
    103 R NULL
    103 Q NULL
    Ny requirement is like:
    id_col stat_col_ reason_col
    101 A|P HPQ|EDU
    102 P HEN
    103 R|Q NULL
    step1- Type tab_type as table of varchar2(32767);
    step2 - I have written a function which returns the pl/sql table type
    create or replace function fn_get_val(id in VARCHAR2)
    return tab_type
    cursor my_cur is
    select id_col,stat_col,reason_col
    from test_table WHERE ID_COL = ID;
    lv_status VARCHAR2(100);
    LV_reason varchar2(200);
    lv_sep CHAR(1);
    lv_disp_stat varchar2(200);
    lv_disp_reason varchar2(200);
    LN_STR NUMBER;
    BEGIN
    lv_tab_data:= tab_type();
    lv_tab_data.extend;
    open my_cur;
    loop
    fetch my_cur into lv_status,lv_reason;
    exit when my_cur%notfound;
    --dbms_output.put_line('my_curr.rowcount'|| my_curr.rowcount);
    lv_disp_stat:= lv_disp_stat||lv_sep||lv_status;
    lv_disp_reason:= lv_disp_reason||lv_sep||lv_reason;
    lv_sep:= '|';
    end loop;
    -- To remove first occurance of (|) pipeline in the string.
    LN_STR := INSTR(lv_str1,'|',1,1);
    IF LN_STR = 1 THEN
    lv_disp_stat := SUBSTR(lv_disp_stat ,2 );
    END IF;
    LN_STR := INSTR(lv_str2,'|',1,1);
    IF LN_STR = 1 THEN
    lv_disp_reason := SUBSTR(lv_disp_reason ,2 );
    END IF;
    lv_tab_data(1) := lv_disp_stat;
    lv_tab_data.extend;
    lv_tab_data(2) := lv_disp_reason;
    return lv_tab_data;
    EXCEPTION
    DBMS_OUTPUT.PUT_LINE('Error in function fn_get_val # '||SQLERRM||' - '||dbms_utility.format_error_backtrace);
    END fn_get_val;
    STEP-3
    I have created one procedure where the above function is called
    CREATE OR REPLACE PROCEDURE my_proc (p_emp_id in Varchar2)
    AS
    lv_tab_ty tab_type;
    CURSOR DET_CUR IS
    SELECT EMP_ID_C,NAME_C,LOCATION
    FROM DETAILS_TABLE
    WHERE EMP_ID_C = p_emp_id;
    type det_tab_ty is table of det_cur%type index by pls_integer;
    lv_det_rec det_tab_ty;
    BEGIN
         lv_tab_ty := fn_get_val(p_emp_id);
         dbms_output.put_line('lv_tab_ty.count is : '||lv_tab_ty.count);
         OPEN DET_CUR;
         LOOP
         FETCH DET_CUR BULK COLLECT INTO lv_det_rec;
         EXIT WHEN DET_CUR%NOTFOUND;
         END LOOP;
         CLOSE DET_CUR;
         IF lv_det_rec.COUNT > 0 THEN
         FOR i IN lv_det_rec.FIRST .. lv_det_rec.LAST
         LOOP
         INSERT INTO other_tab (emp_id_c,name_c,Loc_c,status_c,reason_c) values(lv_det_rec(i).emp_id_c,lv_det_rec(i).NAME_C,lv_det_rec(i).LOCATION,lv_tab_ty(1),lv_tab_ty(2) );
         END LOOP;
         END IF;
    COMMIT;
    EXCEPTIONS
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Error in procedure my_proc # '||SQLERRM||' - '||dbms_utility.format_error_backtrace);
    END my_proc ;
    After exucting the above procedure i am getting the following error.
    lv_tab_ty.count is : 1
    Error # ORA-06533: Subscript beyond count.
    This error is occured when my_curr.rowcount is equal to 0 (cursor defined in the function fn_get_val() ).
    The function fn_get_val() does return null to the pl/sql table variable (lv_tab_ty).
    AND another schenario:
    If
    lv_tab_data.count = 1
    Then how can i handle this situation in the above procedure,because i need both
    lv_tab_data(1)
    and lv_tab_data(2)
    to insert to the OTHER_TABLE in the procedure.
    Please help me to solve this issue.
    Thanks in Advance!!!
    PKM

    You can do it with one query with Tom Kyte's stragg function:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:3431223221768118::::P11_QUESTION_ID:15637744429336
    with test_table(id_col,stat_col,reason_col) as (
    select 101,'A','PQ' from dual union all
    select 101,'A',NULL from dual union all
    select 101,NULL,'EDU' from dual union all
    select 101,'P',NULL from dual union all
    select 102,'P',NULL from dual union all
    select 102,NULL,'HEN' from dual union all
    select 103,'R',NULL from dual union all
    select 103,'Q',NULL from dual
    select id_col,replace(stragg(stat_col),',','|'),replace(stragg(reason_col),',','|')
    from test_table tt
    group by id_colRegards,
    Sayan M.

Maybe you are looking for

  • I have a 990XA-GD55 With One Click Bios II-Am I alone?uefi?

    I created a post not to long ago asking for help with a situation. I bought a new Board 1 week ago. Board was Brand new, never opened... """This Board Is Not suppose to Have A Uefi Bios.....This Board is Not suppose to have One Click Bios II........"

  • Add People in Elements 13 (Second Question)

    This is probably an issue of software stability - possibly tied in with the first and similar titled question (AdobeFan27 - 28 Sept 2014). Tried Troubleshooting face recognition issues in Organizer which didn't help. I have a new load of PSE13 and ha

  • Post Goods Issue - error : Class type does not exist - Message no. VK662

    Hi, I am trying to do Post Goods Issue and getting this error: Class type does not exist When double click on the error, it shows it is a message no vk662. Any help to resolve it is appreciated. Thanks in advance. -Sri

  • How to find username from trace file for deadlock due to user

    This is the info from the trace file. *** 2003-08-18 08:07:40.590 *** SESSION ID:(560.60728) 2003-08-18 08:07:40.560 DEADLOCK DETECTED Current SQL statement for this session: SELECT S.AVAILABLE,GET_AVAIL(S.PRODUCT_ID),S.ON_HAND,S.W_PL,S.PRODUCT_GROUP

  • TIPS(30) : TABLE에 걸려 있는 CONSTRAINT 찾아 보기

    제품 : SQL*PLUS 작성날짜 : 1996-12-27 TIPS(30) : TABLE에 걸려 있는 CONSTRAINT 찾아 보기 ================================================ REM Script: REM tbconst.sql REM REM REM NOTE * Need select access against sys.dba_cons_columns and REM sys.dba_constraints to ru