How to improve performance in the following PL/SQL

I'm running this PL/SQL in a Job step inside a UNIX job, is taking too long to finish and is a simple process to do but definetely there is something that I need to do.
I have to find records that are not included in my T_XREF table from my temporary table T_TEMP, identify those records and insert a new record with values located in the T_TEMP table into the T_XREF table.
T_TEMP has 2 millions records and T_XREF has 12,000 records, I have a Unique IDX in T_TEMP (claim,num_dtl) and a NON UNIQUE IDX by (7 fields).
on the T_XREF table I have 1 UNIQUE IDX (comp_key).
this is part of the PL/SQL:
DECLARE
v_rowid ROWID;
CURSOR c_FixComp1 IS
SELECT DISTINCT sak_acct,ind_split,cde_state,cde_fed,med_a,med_b,ind_cnty
FROM T_TEMP
WHERE claim >= 0;
BEGIN
FOR r_FixComp1 IN c_FixComp1 LOOP
BEGIN
SELECT ROWID
INTO v_rowid
FROM T_XREF x
WHERE x.sak_acct = r_FixComp1.sak_acct
AND x.ind_split = r_FixComp1.ind_split
AND x.cde_state = r_FixComp1.cde_state
AND x.cde_fed = r_FixComp1.cde_fed
AND x.med_a = r_FixComp1.med_a
AND x.med_b = r_FixComp1.med_b
AND x.ind_cnty = r_FixComp1.ind_cnty;
EXCEPTION
WHEN NO_DATA_FOUND THEN
INSERT INTO T_XREF
(comp_key,
sak_acct,
ind_split,
cde_state,
cde_fed,
med_a,
med_b,
ind_cnty)
VALUES
(seq_xref.Nextval,
r_FixComp1.sak_acct,
r_FixComp1.ind_split,
r_FixComp1.cde_state,
r_FixComp1.cde_fedt,
r_FixComp1.med_a,
r_FixComp1.med_b,
r_FixComp1.ind_cnty);
WHEN OTHERS THEN
cnt_notinserted := cnt_notinserted + 1;
END;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
END;
in my Cursor's query I'm forcing to do a IDX (range scan) and the result of that query is only 1300 rec after doing the DISTINCT of those fields. When starts analyzing record by record this simple script takes more than 10 hrs to run!!!
I'll appreciate any advice you can give me. Thanks

The reason your code is slow is that you are doing something that wasn't even best practice in version 7.0.12. Chris Poole is absolutely correct: There is no reason for any procedural code.
Even if there were a valid reason for PL/SQL the row-by-row cursor fetch construct has been obsolete for 6 years.
Do what Chris is suggesting here and then put away the cursor loops and learn how to write this code:
http://www.psoug.org/reference/array_processing.html
Check out the SLOW_WAY and FAST_WAY demos.

Similar Messages

  • How to improve performance of the attached query

    Hi,
    How to improve performance of the below query, Please help. also attached explain plan -
    SELECT Camp.Id,
    rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount,
    (SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
    rCam.AccountKey as AccountKey
    FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
    WHERE Camp.AccountKey = rCam.AccountKey
    AND Camp.AvCampaignKey = rCam.AvCampaignKey
    AND Camp.AccountKey = CamBilling.AccountKey
    AND Camp.CampaignKey = CamBilling.CampaignKey
    AND rCam.AccountKey = xSite.AccountKey
    AND rCam.AvSiteKey = xSite.AvSiteKey
    AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
    to_date('01-01-2011', 'DD-MM-YYYY')
    GROUP By rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount
    Explain Plan :-
    Description Object_owner Object_name Cost Cardinality Bytes
    SELECT STATEMENT, GOAL = ALL_ROWS 14 1 13
    SORT AGGREGATE 1 13
    VIEW GEMINI_REPORTING 14 1 13
    HASH GROUP BY 14 1 103
    NESTED LOOPS 13 1 103
    HASH JOIN 12 1 85
    TABLE ACCESS BY INDEX ROWID GEMINI_REPORTING RCAMSIT 2 4 100
    NESTED LOOPS 9 5 325
    HASH JOIN 7 1 40
    SORT UNIQUE 2 1 18
    TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY SITE 2 1 18
    INDEX RANGE SCAN GEMINI_PRIMARY SITE_I0 1 1
    TABLE ACCESS FULL GEMINI_PRIMARY SITE 3 27 594
    INDEX RANGE SCAN GEMINI_REPORTING RCAMSIT_I 1 1 5
    TABLE ACCESS FULL GEMINI_PRIMARY CAMPAIGN 3 127 2540
    TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY CAMBILLING 1 1 18
    INDEX UNIQUE SCAN GEMINI_PRIMARY CAMBILLING_U1 0 1

    duplicate thread..
    How to improve performance of attached query

  • How to improve Performance of the Statements.

    Hi,
    I am using Oracle 10g. My problem is when i am Execute & fetch the records from the database it is taking so much time. I have created Statistics also but no use. Now what i have to do to improve the Performance of the SELECT, INSERT, UPDATE, DELETE Statements.
    Is it make any differents because i am using WindowsXP, 1 GB RAM in Server Machine, and WindowsXP, 512 GB RAM in Client Machine.
    Pls. Give me advice for me to improve Performance.
    Thank u...!

    What and where to change parameters and values ?Well, maybe my previous post was not clear enough, but if you want to keep your job, you shouldn't change anything else on init parameter and you shouldn't fall in the Compulsive Tuning Disorder.
    Everyone who advise you to change some parameters to some value without any more info shouldn't be listen.
    Nicolas.

  • How to improve performance of the program

    I have this program which loops 3 times and in each loop it creates differents variants and calls the program passing these variants. Now the pple who run this program say that the performance of the program decreased. They say that if this run it takes 3times more time than running individual program 3 times seperately. Any ideas on how i should go about this. Seems like with in the loop the all the information about the second program which is being called is stored.Any ideas on how to clear the program memory with in the loop.

    Let me explain in little more detail. The program which i wrote create variants in a loop and passes them to the report which is also called inside the loop like.
    do 3 times.
    *create variant.
    submit <program> X via selection-screen using tables....
    enddo.
    Now what this report does is it just retrieves like 500,000 records and updates them to another table.

  • How to improve performance of the below code.

    Hello.
    This below code is show 80% database performance in runtime analysis ( transaction SE30). I am using view KNA1VV for retrieving data using customer and sales area from selection screen.
    Please advice how can I improve the performance of below code.
    Fetch the customer details from view KNA1VV
      SELECT kunnr
             vkorg
             vtweg
             spart
             land1
             name1
             ort01
             pstlz
             regio
             stras
            INTO TABLE t_cust
            FROM kna1vv
      WHERE kunnr IN s_kunnr
      AND   vkorg IN s_vkorg
      AND   vtweg IN s_vtweg
      AND   spart IN s_spart
      AND   loevm = space
      AND   loevm_knvv = space.
      IF sy-subrc EQ 0.
        SORT t_cust BY kunnr.
      ELSE.
        w_flag = c_true_x.
      ENDIF.
    Fetch customers for entered company code
      IF NOT t_cust[] IS INITIAL AND NOT s_bukrs IS INITIAL.
        SELECT kunnr
               FROM knb1
               INTO TABLE lt_knb1
               FOR ALL ENTRIES IN t_cust
        WHERE kunnr = t_cust-kunnr
        AND   bukrs IN s_bukrs
        AND   loevm = space.
    Thanks,

    80% is just a relation and must not be problematic, what about the absolute runtime, is that acceptable?
    Also, your range S_KUNNR could contain anything from a single value (super fast) to nothing (probably slow, depends on number of entries in KNA1VV), so what do you expect here?
    Thomas

  • How to improve performance of attached query

    Hi,
    How to improve performance of the below query, Please help. also attached explain plan -
    SELECT Camp.Id,
    rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount,
    (SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
    rCam.AccountKey as AccountKey
    FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
    WHERE Camp.AccountKey = rCam.AccountKey
    AND Camp.AvCampaignKey = rCam.AvCampaignKey
    AND Camp.AccountKey = CamBilling.AccountKey
    AND Camp.CampaignKey = CamBilling.CampaignKey
    AND rCam.AccountKey = xSite.AccountKey
    AND rCam.AvSiteKey = xSite.AvSiteKey
    AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
    to_date('01-01-2011', 'DD-MM-YYYY')
    GROUP By rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount
    Explain Plan :-
    Description Object_owner Object_name Cost Cardinality Bytes
    SELECT STATEMENT, GOAL = ALL_ROWS 14 1 13
    SORT AGGREGATE 1 13
    VIEW GEMINI_REPORTING 14 1 13
    HASH GROUP BY 14 1 103
    NESTED LOOPS 13 1 103
    HASH JOIN 12 1 85
    TABLE ACCESS BY INDEX ROWID GEMINI_REPORTING RCAMSIT 2 4 100
    NESTED LOOPS 9 5 325
    HASH JOIN 7 1 40
    SORT UNIQUE 2 1 18
    TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY SITE 2 1 18
    INDEX RANGE SCAN GEMINI_PRIMARY SITE_I0 1 1
    TABLE ACCESS FULL GEMINI_PRIMARY SITE 3 27 594
    INDEX RANGE SCAN GEMINI_REPORTING RCAMSIT_I 1 1 5
    TABLE ACCESS FULL GEMINI_PRIMARY CAMPAIGN 3 127 2540
    TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY CAMBILLING 1 1 18
    INDEX UNIQUE SCAN GEMINI_PRIMARY CAMBILLING_U1 0 1

    duplicate thread..
    How to improve performance of attached query

  • How to improve performance of query

    Hi all,
    How to improve performance of query.
    please send :
    [email protected]
    thanks in advance
    bhaskar

    hi
    go through the following links for performance
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/cccad390-0201-0010-5093-fd9ec8157802
    http://www.asug.com/client_files/Calendar/Upload/ASUG%205-mar-2004%20BW%20Performance%20PDF.pdf
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/1955ba90-0201-0010-d3aa-8b2a4ef6bbb2

  • How to improve Performance for Select statement

    Hi Friends,
    Can  you please help me in improving the performance of the following query:
    SELECT SINGLE MAX( policyterm ) startterm INTO (lv_term, lv_cal_date) FROM zu1cd_policyterm WHERE gpart = gv_part GROUP BY startterm.
    Thanks and Regards,
    Johny

    long lists can not be produced with  a SELECT SINGLE, there is also nothing to group.
    But I guess the SINGLE is a bug
    SELECT MAX( policyterm ) startterm
                  INTO (lv_term, lv_cal_date)
                  FROM zu1cd_policyterm
                  WHERE gpart = gv_part
                  GROUP BY startterm.
    How many records are in zu1cd_policyterm ?
    Is there an index starting with gpart?
    If first answer is 'large' and second 'no'   =>   slow
    What is the meaning of gpart?  How many different values can it assume?
    If many different values then an index makes sense, if you are allowed to create
    an index.
    Otherwise you must be patient.
    Siegfried

  • How to improve performance of MediaPlayer?

    I tried to use the MediaPlayer with a On2 VP6 flv movie.
    Showing a video with a resolution of 1024x768 works.
    Showing a video with a resolution of 1280x720 and a average bitrate of 1700 kb/s leads to a delay of the video signal behind the audio signal of a couple of seconds. VLC, Media Player Classic and a couple of other players have no problem with the video. Only the FX MediaPlayer shows a poor performance.
    Additionally mouse events in a second stage (the first stage is used for the video) are not processed in 2 of 3 cases. If the MediaPlayer is switched off, the mouse events work reliable.
    Does somebody know a solution for this problems?
    Cheers
    masim

    duplicate thread..
    How to improve performance of attached query

  • How to improve performance of Siebel Configurator

    Hi All,
    We are using Siebel Configurator to model the item structures. We wrote few constraint rules on that. But while launching the configurator it is taking more time to open.
    Even without rules also it is behaving in the same manner.
    Any inputs on this could be highly appreciated
    RAM

    duplicate thread..
    How to improve performance of attached query

  • I have a MAC Pro from 2011 currently running MAC OS 10.9.5.  This weekend I cloned the MAC HD drive to a new SSD drive for improved performance.  The clone was completed successfully with no errors.  After the clone completed I successfull restarted my sy

    I have a MAC Pro from 2011 currently running MAC OS 10.9.5.  This weekend I cloned the MAC HD drive to a new SSD drive for improved performance.  The clone was completed successfully with no errors.  After the clone completed I successfully restarted my system using the SSD as the boot device.  I then successfully tested all of my products, including Photoshop CS6 and all of its plug-ins.  I successfully tested the key features that I frequently use.  Today while attempting to launch Photoshop CS6 a message is being displayed indicating that a scratch disk cannot be found.  All drives are available on the system via the Finder and Disk Utility.  I can access all drives including the old MAC HD which is no longer the boot device.  I've even attempted to launch Photoshop from the old device yet the same error persist.  Is there a way to review/edit/change Photoshop preferences if Photoshop doesn't launch?  I've even restarted my system several times to see if that would resolve the issues.  Does anyone have any recommendations for this issue?  Have you previously address this issue? 
    Thank you Gregg Williams

    Boilerplate text:
    Reset Preferences
    http://forums.adobe.com/thread/375776
    1) Close the program and press Ctrl+Alt+Shift/Cmd+Option+Shift during startup (not reversible)
    or
    2) Move the Folder. See:
    http://www.bugge.com/Family-and-friends/Illy/illy.html
    --OB

  • How to improve performance of insert statement

    Hi all,
    How to improve performance of insert statement
    I am inserting 1lac records into table it takes around 20 min..
    Plz help.
    Thanx In Advance.

    I tried :
    SQL> create table test as select * from dba_objects;
    Table created.
    SQL> delete from test;
    3635 rows deleted.
    SQL> commit;
    Commit complete.
    SQL> select count(*) from dba_extents where segment_name='TEST';
    COUNT(*)
    4
    SQL> insert /*+ APPEND */ into test select * from dba_objects;
    3635 rows created.
    SQL> commit;
    Commit complete.
    SQL> select count(*) from dba_extents where segment_name='TEST';
    COUNT(*)
    6
    Cheers, Bhupinder

  • How to generate interface like the following?

    How to generate interface like the following? It is very practical.
    http://dl.getdropbox.com/u/212185/WebPics/AdobeForum_001.png
    Thanks!
    hanyang

    Interesting. I know much of that is possible, but it'd be heavy customization work. There's no 'table' type in the ADM, nor is there anything about lists with columns.
    That said, you can pretty much customize the drawing of a list entry to your heart's content so I don't see why you could do it manually. Drawing text is done by specifying boxes so it should be fairly easy to do that part.
    As for making a combo box pop up when you click...that I'm far less sure about. Again, catching the click and figuring out what column it's in shouldn't be too hard, so long as you take the proper care in setting up your widget & variables. And you *might* be able to create a combo box on the fly and position it appropriately -- though without a clear z-order I can't guarantee that it wouldn't appear *behind* the list. The trouble I see is figuring out how to dismiss the combo box when finished with it. You'd have to be careful to catch a lot of events like the panel losing focus and clicks to anything else on the panel and hooking them all up to let the list know it's time to dismiss the temporary combo box.

  • Some Import Operations failed to perform. The following files could not be imported because they cou

    Some Import Operations failed to perform. The following files could not be imported because they could not be read....(then all the files that I checked do not get imported

    As a Test:
    Hold down the option (or alt) key and launch iPhoto. From the resulting menu select 'Create Library'
    Import a few pics into this new, blank library. Is the Problem repeated there?

  • What does this mean and how do I fix it: "The following warnings and errors were found during the validation of the current project:  - There appears to be a broken asset in your project. Correct this problem before burning this project."

    What does this mean and how do I fix it: "The following warnings and errors were found during the validation of the current project:  - There appears to be a broken asset in your project. Correct this problem before burning this project."

    It means that iDVD has found a problem with one of the movies added to the project.  Did you edit the movie after it had been added to the project.
    Create a new project and add your assets, movies, slides, etc. again and follow this workflow to help ensure the best quality video DVD:
    Once you have the project as you want it save it as a disk image via the  File ➙ Save as Disk Image  menu option.  This will separate the encoding process from the burn process. 
    To check the encoding mount the disk image and launch DVD Player and play it.  If it plays OK with DVD Player the encoding was good.
    Then burn to disk with Disk Utility or Toast at the slowest speed available (2x-4x) to assure the best burn quality.  Always use top quality media:  Verbatim, Maxell or Taiyo Yuden DVD-R are the most recommended in these forums.
    OT

Maybe you are looking for

  • Oracle Application Server-Unable to start "WebCache" process.

    Hello, Using "Oracle Application Server" 10g. Right Now, I am getting below error while starting oracle application server by using below commands. ./opmnctl startall ( To start entire oracle service modules) ./opmnctl startproc process-type=WebCache

  • Copying DVD to Hard Disc

    I ha a non copywright DVD that I want to copy to be able to play from my Mac rather than from the DVD. The DVD has 2 TS folders (audio & video) Can someone enlighten me on the best way to import to my Mac please? All help appreciated - thanks Patrick

  • CD uploaded in different language

    Welll.. a long time ago i tried to upload my cd into my iTunes. I guess i accidentially clicked the wrong item from a list, so all of the songs were in..corean? im not sure, possibly chinese. anyway i just put it in again today and i have no idea wha

  • Lion requests password for programs frequently

    OS asks me for keychain passwords for Mail, Address book, and Safari. This did not start immediately after installing Lion but I wonder if settings are changed when updates to the Lion cluster of programs are downloaded. I have experienced these chan

  • Im running mac os x 10.6.8, at present. should i update and if so to snow leopard or lion. what will i gain, thanks

    im running a mac on osx 10.6.8 at present. should i update to lion or leopard and if so what would i gain. can you put it in laymans terms as im not realy computer lit..thanks