How can I load my data faster?  Is there a SQL solution instead of PL/SQL?

11.2.0.2
Solaris 10 sparc
I need to backfill invoices from a customer. The raw data has 3.1 million records. I have used pl/sql to load these invoices into our system (dev), however, our issue is the amount of time it's taking to run the load - effectively running at approx 4 hours. (Raw data has been loaded into a staging table)
My research keeps coming back to one concept: sql is faster than pl/sql. Where I'm stuck is the need to programmatically load the data. The invoice table has a sequence on it (primary key = invoice_id)...the invoice_header and invoice_address tables use the invoice_id as a foreign key. So my script takes advantage of knowing the primary key and uses that on the subsequent inserts to the subordinate invoice_header and invoice_address tables, respectively.
My script is below. What I'm asking is if there are other ideas on the quickest way to load this data...what am I not considering? I have to load the data in dev, qa, then production so the sequences and such change between the environments. I've dummied down the code to protect the customer; syntax and correctness of the code posted here (on the forum) is moot...it's only posted to give the framework for what I currently have.
Any advice would be greatly appreciated; how can I load the data faster knowing that I need to know sequence values for inserts into other tables?
DECLARE
   v_inv_id        invoice.invoice_id%TYPE;
   v_inv_addr_id    invoice_address.invoice_address_id%TYPE;
   errString        invoice_errors.sqlerrmsg%TYPE;
   v_guid          VARCHAR2 (128);
   v_str           VARCHAR2 (256);
   v_err_loc       NUMBER;
   v_count         NUMBER := 0;
   l_start_time    NUMBER;
   TYPE rec IS RECORD
      BILLING_TYPE             VARCHAR2 (256),
      CURRENCY                 VARCHAR2 (256),
      BILLING_DOCUMENT         VARCHAR2 (256),
      DROP_SHIP_IND            VARCHAR2 (256),
      TO_PO_NUMBER        VARCHAR2 (256),
      TO_PURCHASE_ORDER   VARCHAR2 (256),
      DUE_DATE                 DATE,
      BILL_DATE                DATE,
      TAX_AMT                  VARCHAR2 (256),
      PAYER_CUSTOMER           VARCHAR2 (256),
      TO_ACCT_NO          VARCHAR2 (256),
      BILL_TO_ACCT_NO          VARCHAR2 (256),
      NET_AMOUNT               VARCHAR2 (256),
      NET_AMOUNT_CURRENCY      VARCHAR2 (256),
      ORDER_DT             DATE,
      TO_CUSTOMER         VARCHAR2 (256),
      TO_NAME             VARCHAR2 (256),
      FRANCHISES       VARCHAR2 (4000),
      UPDT_DT                  DATE
   TYPE tab IS TABLE OF rec
                  INDEX BY BINARY_INTEGER;
   pltab           tab;
   CURSOR c
   IS
      SELECT   billing_type,
               currency,
               billing_document,
               drop_ship_ind,
               to_po_number,
               to_purchase_order,
               due_date,
               bill_date,
               tax_amt,
               payer_customer,
               to_acct_no,
               bill_to_acct_no,
               net_amount,
               net_amount_currency,
               order_dt,
               to_customer,
               to_name,
               franchises,
               updt_dt
        FROM   BACKFILL_INVOICES;
BEGIN
   l_start_time := DBMS_UTILITY.get_time;
   OPEN c;
   LOOP
      FETCH c
      BULK COLLECT INTO pltab
      LIMIT 1000;
      v_err_loc := 1;
      FOR i IN 1 .. pltab.COUNT
      LOOP
         BEGIN
            v_inv_id :=  SEQ_INVOICE_ID.NEXTVAL;
            v_guid := 'import' || TO_CHAR (CURRENT_TIMESTAMP, 'hhmissff');
            v_str := str_parser (pltab (i).FRANCHISES); --function to string parse  - this could be done in advance, yes.
            v_err_loc := 2;
            v_count := v_count + 1;
            INSERT INTO    invoice nologging
                 VALUES   (v_inv_id,
                           pltab (i).BILL_DATE,
                           v_guid,
                           '111111',
                           'NONE',
                           TO_TIMESTAMP (pltab (i).BILL_DATE),
                           TO_TIMESTAMP (pltab (i).UPDT_DT),
                           'READ',
                           'PAPER',
                           pltab (i).payer_customer,
                           v_str,
                           '111111');
            v_err_loc := 3;
            INSERT INTO    invoice_header nologging
                 VALUES   (v_inv_id,
                           TRIM (LEADING 0 FROM pltab (i).billing_document), --invoice_num
                           NULL,
                           pltab (i).BILL_DATE,                 --invoice_date
                           pltab (i).TO_PO_NUMBER,
                           NULL,
                           pltab (i).net_amount,
                           NULL,
                           pltab (i).tax_amt,
                           NULL,
                           NULL,
                           pltab (i).due_date,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           TO_TIMESTAMP (SYSDATE),
                           TO_TIMESTAMP (SYSDATE),
                           PLTAB (I).NET_AMOUNT_CURRENCY,
                           (SELECT   i.bc_value
                              FROM   invsvc_owner.billing_codes i
                             WHERE   i.bc_name = PLTAB (I).BILLING_TYPE),
                           PLTAB (I).BILL_DATE);
            v_err_loc := 4;
            INSERT INTO    invoice_address nologging
                 VALUES   (invsvc_owner.SEQ_INVOICE_ADDRESS_ID.NEXTVAL,
                           v_inv_id,
                           'BLAH INITIAL',
                           pltab (i).BILL_DATE,
                           NULL,
                           pltab (i).to_acct_no,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           SYSTIMESTAMP,
                           NULL);
            v_err_loc := 5;
            INSERT INTO    invoice_address nologging
                 VALUES   ( SEQ_INVOICE_ADDRESS_ID.NEXTVAL,
                           v_inv_id,
                           'BLAH',
                           pltab (i).BILL_DATE,
                           NULL,
                           pltab (i).TO_ACCT_NO,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           SYSTIMESTAMP,
                           NULL);
            v_err_loc := 6;
            INSERT INTO    invoice_address nologging
                 VALUES   ( SEQ_INVOICE_ADDRESS_ID.NEXTVAL,
                           v_inv_id,
                           'BLAH2',
                           pltab (i).BILL_DATE,
                           NULL,
                           pltab (i).TO_CUSTOMER,
                           pltab (i).to_name,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           SYSTIMESTAMP,
                           NULL);
            v_err_loc := 7;
            INSERT INTO    invoice_address nologging
                 VALUES   ( SEQ_INVOICE_ADDRESS_ID.NEXTVAL,
                           v_inv_id,
                           'BLAH3',
                           pltab (i).BILL_DATE,
                           NULL,
                           'SOME PROPRIETARY DATA',
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           NULL,
                           SYSTIMESTAMP,
                           NULL);
            v_err_loc := 8;
            INSERT
              INTO    invoice_event nologging (id,
                                                         eid,
                                                         root_eid,
                                                         invoice_number,
                                                         event_type,
                                                         event_email_address,
                                                         event_ts)
            VALUES   ( SEQ_INVOICE_EVENT_ID.NEXTVAL,
                      '111111',
                      '222222',
                      TRIM (LEADING 0 FROM pltab (i).billing_document),
                      'READ',
                      'some_user@some_company.com',
                      SYSTIMESTAMP);
            v_err_loc := 9;
            INSERT INTO   backfill_invoice_mapping
                 VALUES   (v_inv_id,
                           v_guid,
                           pltab (i).billing_document,
                           pltab (i).payer_customer,
                           pltab (i).net_amount);
            IF v_count = 10000
            THEN
               COMMIT;              
            END IF;
         EXCEPTION
            WHEN OTHERS
            THEN
               errString := SQLERRM;
               INSERT INTO   backfill_invoice_errors
                    VALUES   (
                                pltab (i).billing_document,
                                pltab (i).payer_customer,
                                errString || ' ' || v_err_loc
               COMMIT;
         END;
      END LOOP;
      v_err_loc := 10;
      INSERT INTO   backfill_invoice_timing
           VALUES   (
                       ROUND ( (DBMS_UTILITY.get_time - l_start_time) / 100,
                              2)
                       || ' seconds.',
                       (SELECT   COUNT (1)
                          FROM   backfill_invoice_mapping),
                       (SELECT   COUNT (1)
                          FROM   backfill_invoice_errors),
                       SYSDATE
      COMMIT;
      EXIT WHEN c%NOTFOUND;
   END LOOP;
   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      errString := SQLERRM;
      INSERT INTO   backfill_invoice_errors
           VALUES   (NULL, NULL, errString || ' ' || v_err_loc);
      COMMIT;
END;

Hello
You could use insert all in your case and make use of sequence.NEXTVAL and sequence.CURRVAL like so (excuse any typos - I can't test without table definitions). I've done the first 2 tables, so it's just a matter of adding the rest in...
INSERT ALL
     INTO      invoice nologging
                VALUES   (     SEQ_INVOICE_ID.NEXTVAL,
                               BILL_DATE,
                                my_guid,
                                '111111',
                                'NONE',
                                CAST(BILL_DATE AS TIMESTAMP),
                                CAST(UPDT_DT AS TIMESTAMP),
                                'READ',
                                'PAPER',
                                payer_customer,
                                parsed_francises,
                                '111111'
     INTO      invoice_header
          VALUES   (      SEQ_INVOICE_ID.CURRVAL,
                    TRIM (LEADING 0 FROM billing_document), --invoice_num
                    NULL,
                    BILL_DATE,                 --invoice_date
                    TO_PO_NUMBER,
                    NULL,
                    net_amount,
                    NULL,
                    tax_amt,
                    NULL,
                    NULL,
                    due_date,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    NULL,
                    SYSTIMESTAMP,
                    SYSTIMESTAMP,
                    NET_AMOUNT_CURRENCY,
                    bc_value,
                    BILL_DATE)
     SELECT 
     src.billing_type,
          src.currency,
          src.billing_document,
          src.drop_ship_ind,
          src.to_po_number,
          src.to_purchase_order,
          src.due_date,
          src.bill_date,
          src.tax_amt,
          src.payer_customer,
          src.to_acct_no,
          src.bill_to_acct_no,
          src.net_amount,
          src.net_amount_currency,
          src.order_dt,
          src.to_customer,
          src.to_name,
          src.franchises,
          src.updt_dt,
          str_parser (src.FRANCHISES) parsed_franchises,
          'import' || TO_CHAR (CURRENT_TIMESTAMP, 'hhmissff') my_guid,
          i.bc_value
        FROM        BACKFILL_INVOICES src,
             invsvc_owner.billing_codes i
     WHERE   i.bc_name = src.BILLING_TYPE;Some things to note
1. Don't commit in a loop - you only add to the run time and load on the box ultimately reducing scalability and removing transactional integrity. Commit once at the end of the job.
2. Make sure you specify the list of columns you are inserting into as well as the values or columns you are selecting. This is good practice as it protects your code from compilation issues in the event of new columns being added to tables. Also it makes it very clear what you are inserting where.
3. If you use WHEN OTHERS THEN... to log something, make sure you either rollback or raise the exception. What you have done in your code is say - I don't care what the problem is, just commit whatever has been done. This is not good practice.
HTH
David
Edited by: Bravid on Oct 13, 2011 4:35 PM

Similar Messages

  • How can i get todays date as an yyyy-MM-dd format instead of Time stamp

    how can i get todays date as an yyyy-MM-dd format instead of Time stamp,i try to do it in the fallowing way
    <code>
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
         java.util.Date d = new java.util.Date();
              String s = d+"";
    Calendar cal1 = Calendar.getInstance();
         try{
         cal1.setTime(sdf.parse(s));
    }catch(Exception e){}
    </code>
    but i could not able to get,it throws error as an java.text.ParseException: Unparseable date: "Thu Jan 24 11:43:32 EST 2002" ,pl suggest me any solution.any help would be appreciated.
    Regards.

    Does string s have to end with ""?
    Try doing sdf.format(d) instead.

  • How can I load a data in multiple period with a rule files?

    Hi!
    I need to create a rule file the permit me to load a record with multiple period.
    How can I do it?
    Thanks in advance.
    Bye

    As Glenn said, these two types are the typical input files.
    two ways that I can easily think of, but there are more.
    1. Have a row memberwith the period so for sample basic, the row would look lik
    cola,ny,actual,sales,Jan,100
    First case in the rule file you have to map all the member fileds with the dimension name and the data column with the data field.
    2. Have the data for each month as as the column members
    Here is the header followed by a data sample(again for sample basic)
    Product,Market,Scenario,Measure,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
    1oo-10,NY,Actual,Sales,100,100,100,100,100,100,100,010,122,111,222,333
    Second case in the rule file you have to map all the member fileds with the corresponding dimension name and the multiple data columns with the corresponding member names for that dimension.

  • How can I load xcel data into simulate arbitary signal VI

    Hello,
    I am using the labview arbitary signal creator , now i have a pattern which can be easily created in microsoft xcel but i need to load the data in the simulate arbitary signal VI so essentially i need to convert an xcel file into a LVM file . Can i somehow load the xcel data as LVM data.
    Thanks
    Ams

    Ams wrote:
    Hello,
    I am using the labview arbitary signal creator , now i have a pattern which can be easily created in microsoft xcel but...
    If you can generate it in excel, it would be even easier to generate it directly in LabVIEW. Are we still talking about the staircase funcion?
    http://forums.ni.com/ni/board/message?board.id=170​&message.id=221036
    LabVIEW Champion . Do more with less code and in less time .

  • How can I load the data of Manager Beans into an Array?

    Hi all!
    I have a problem when use the ADF model layer (JDeveloper 10g). I want to load the data of a Manager Bean into Array(such as: Array in JavaScript).But I don't know any ways to do.
    Are there any ways to do that?
    Please, help me!
    Thanks so much!

    Hi,
    there is a fundamental difference between an array in Java and an array in JavaScript as the latter is added to the output page while the first sits in a Java class on the server.
    Populating a Java array from a managed bean is straight froward: Just create the Array, loop through the source of the data - ADF binding or the ADF Faces table component - and fill it.
    For a JavaScript Array I would suggest to write the array into a js file and reference it from the web page (which might cause concurrency issues).
    Frank

  • How can I load iCal data into Calendar and Address Book data into Contacts?

    I just bought a MacBook Pro running Yosemite. Migration Assistant could not read the Backup of my old, dead iMac, so I have been transferring data manually. So far Contacts and Calendar are the only Apps I have not been able to set up.

    What OS was the iMac running? I ask because where data is stored can change.

  • How can firefox load a complete page of a game in facebook instead of halfpage?

    When I play zynga games in facebook (mafia wars), the page won't show completely. It starts normally but the game won't show completely even if I scroll down it would still be incomplete.

    You're welcome.
    Thanks for reporting the culprit, it help others with the same problem who read this thread.

  • HT1338 I have macbook without a firewire port, I have usb 2.0 port, now my os is not working I can not get through apple logo loading , I can not enter safe mode, I can only enter one user mode, how can I backup my data, I have very important data in my h

    I have macbook without a firewire port, I have usb 2.0 port, now my os is not working I can not get through apple logo loading , I can not enter safe mode, I can only enter one user mode, how can I backup my data, I have very important data in my hdd

    Here is what worked for me:
      My usb hub, being usb2, was too fast. I moved the wire to a usb port directory on my pc. That is a usb1 port which is slow enough to run your snyc.

  • How can I load data into table with SQL*LOADER

    how can I load data into table with SQL*LOADER
    when column data length more than 255 bytes?
    when column exceed 255 ,data can not be insert into table by SQL*LOADER
    CREATE TABLE A (
    A VARCHAR2 ( 10 ) ,
    B VARCHAR2 ( 10 ) ,
    C VARCHAR2 ( 10 ) ,
    E VARCHAR2 ( 2000 ) );
    control file:
    load data
    append into table A
    fields terminated by X'09'
    (A , B , C , E )
    SQL*LOADER command:
    sqlldr test/test control=A_ctl.txt data=A.xls log=b.log
    datafile:
    column E is more than 255bytes
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)

    Check this out.
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch06.htm#1006961

  • Hallo My system runs slow. how can i reorganize the date, that the pc runs faster? In the window world i hade to delete some fils. how it work in the apple world?

    Hallo My system runs slow. how can i reorganize the date, that the pc runs faster? In the window world i hade to delete some fils. how it work in the apple world?

    See these:
    Switching from Windows to Mac OS X,
    Basic Tutorials on using a Mac,
    Mac OS X keyboard shortcuts,
    Anatomy of a Mac,
    MacTips,
    Switching to Mac Superguide, and
    Switching to the Mac: The Missing Manual, Mountain Lion Edition.
    Additionally, *Texas Mac Man* recommends:
    Quick Assist,
    Welcome to the Switch To A Mac Guides,
    Take Control E-books, and
    A guide for switching to a Mac.
    Once you get familiar with the Mac, see:
    Mac Maintenance Quick Assist,
    Mac OS X speed FAQ,
    Speeding up Macs,
    How to Speed up Macs, ,
    Macintosh OS X Routine Maintenance,
    Essential Mac Maintenance: Get set up,
    Essential Mac Maintenance: Rev up your routines,
    Maintaining OS X, 
    Five Mac maintenance myths and
    Myths of required versus not required maintenance for Mac OS X for information.

  • How can we load a LOBS data usng Sql loader?

    How can we load a LOBS data usng Sql loader?

    Did you go through SQL Loader documentation?
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_loading.htm#i1006803

  • How can we view the data asociated with Request ID

    Hi All,
    I have data loaded in an ODS there are multiple files loaded in this ODS. Now i want to view data for a perticuler request OR i want to know how can we know the data associated with a perticular request.
    Please help me out.
    Thanks & Regards
    Amit Kumar

    Copy the request number (not request ID) from the ODS manage screen, Goto RSRQ give the request number and execute. it shows the monitor screen- now goto PSA from the top and check the data. But this possible only if you are loading data to PSA also along with ODS.
    Otherwise, Goto Display Data of ODS from the right click on it -- in the selection screen give the Request ID that you want to check the data. Then it displays only that request data.
    Hope this helps.
    Veerendra.
    Edited by: denduluri veerendra kumar on Dec 1, 2009 12:40 PM
    Edited by: denduluri veerendra kumar on Dec 1, 2009 12:43 PM

  • I have hierarchy data in R/3 side how will i load that data from R/3 to BW

    Hi all,
    i have my hierarchy data in the R/3 side how will i load that data from  R/3 to BW side
    Regard
    Kiran Kumar

    Hi Kiran,
    Here is the procedure:
    1.      In the Data Warehousing Workbench under Modeling, select the InfoSource tree.
    2.      Select the InfoSource (with direct update) for the InfoObject, to which you want to load the hierarchy.
    3.      Choose Additional Functions® Create Transfer Rules from the context menu of the hierarchy table object for the InfoObject. The Assign Source System dialog box appears.
    4.      Select the source system from which the hierarchy is to be loaded. The InfoSource maintenance screen appears.
    ○       If the DataSource only supports the transfer method IDoc, then only the transfer structure is displayed (tab page DataSource/Transfer Structure).
    ○       If the DataSource also supports transfer method PSA, you can maintain the transfer rules (tab page Transfer Rules).
    If it is possible and useful, we recommend that you use the transfer method PSA and set the indicator Expand Leaf Values and Node InfoObjects. You can then also load hierarchies with characteristics whose node name has a length >32.
    5.      Save your entries and go back. The InfoSource tree for the Data Warehousing Workbench is displayed.
    6.      Choose Create InfoPackage from the context menu (see Maintaining InfoPackages). The Create InfoPackage dialog box appears.
    7.      Enter the description for the InfoPackage. Select the DataSource (data element Hierarchies) that you require and confirm your entries.
    8.      On the Tab Page: Hierarchy Selection, select the hierarchy that you want to load into your BI system.
    Specify if the hierarchy should be automatically activated after loading or be marked for activation.
    Select an update method (Full Update, Insert Subtree, Update Subtree).
    If you want to load a hierarchy from an external system with BAPI functionality, make BAPI-specific restrictions, if necessary.
    9.      If you want to load a hierarchy from a flat file, maintain the tab page: external data.
    10.      Maintain the tab page: processing.
    11.      Maintain the tab page: updating.
    12.      To schedule the InfoPackage, you have the following options:
    ○       (Manually) in the scheduler, see Scheduling InfoPackages
    ○       (Automatically) using a process chain (see Loading Hierarchies Using a Process Chain)
    When you upload hierarchies, the system carries out a consistency check, making sure that the hierarchy structure is correct. Error messages are logged in the Monitor. You can get technical details about the error and how to correct it in the long text for the respective message.
    For more info visit this help pages on SAP Help:
    http://help.sap.com/saphelp_nw04s/helpdata/en/80/1a6729e07211d2acb80000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_nw04s/helpdata/en/3d/320e3d89195c59e10000000a114084/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/80/1a6729e07211d2acb80000e829fbfe/frameset.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/4dae0795-0501-0010-cc96-fe3a9e8959dc
    Cheers,
    Habeeb

  • How can i convert the data from mutiple-table to the other database(MSSQL)?

    Dears,
    How can i convert the data from mutiple-table to the other database such as MS-SQL?
    I have a third party system based on MS-SQL 2000.
    Now we want to make a integration between SAP R/3(Oracle) and SQL server.
    When my user releases the purchase order in R/3, the application we coded will convert the releated data to the temp database on the SQL server.
    But i don't know which tools will help me reach the purpose.  BAPI, LSMW, IDoc... ???
    Would anybody tell me which way is better and how to do?
    Thanks a lot!
    Kevin Wang

    Hello Kevin,
    The question to use which method depend on your detail requirements. If you use BAPI, you need to find which Bapi can provide the data you want. Bapi normally use as a function called by external system. So you need to develop an external program like VB/Java to call this Bapi and move it to SQL. LSMW is use when you want to upload data from an external system to SAP. So it does not serve your requirement. Idoc can be use to export data to an external system. Again like Bapi, you need to find what Idoc can provide the data you want. However, it does not any programming from the external system. If I were you, based on your requirements, I think writing an Abap program that read the data you want and download it to NT/SQL server will be faster and easier.

  • How can we do the data migration between Oracle Applications and SAP R/3.

    Hi All,
    How can we do the data migration between Oracle Applications and SAP R/3 system.What are all the possible ways to move bulk data from Oracle Apps to SAP r/3 system.
    Provide any 3rd party tools which supports data migration and also pls rpovide the SAP's own data migration tools with supports the above feature.
    Awaiting for best possible solution.
    Thanks in advance.
    Regards
    Dharmaraju

    the 3rd party tool is ETL , you can use ETL tool and the prepare the load files then you can use LSMW method to upload the data to SAP.

Maybe you are looking for