Query for Performance tuning

Hi,
I have attached my query and explain plan for that query. This create statement takes around 1.5 hrs for 200K records.
Is there any way to tune the query.
CREATE TABLE SC1.TMP_MP_XYZ
PARALLEL 4 TABLESPACE FT_WORKAREA NOLOGGING AS
SELECT /*+ ORDERED USE_HASH(x,d) INDEX_FFS(x) PARALLEL(d,4) */
d.ROWID dis_rowid
FROM SC2.TMP_GLOBAL PARTITION (PM200802) x,
SC1.ba_DISP_XX PARTITION (PM200802) d
WHERE x.dsp_hash IN
(d.dsp_hash,
TRUNC (d.dsp_hash, -14),
TRUNC (d.dsp_hash, -7),
TRUNC (d.dsp_hash, -14) + MOD (d.dsp_hash, POWER (10, 7))
AND LOWER (d.url_name) LIKE x.rule || '%'
AND BITAND (d.xflag, 1) = 0
AND BITAND (d.xflag, 1) = 0
Statement Id=14 Type=TABLE ACCESS
Cost=17004 TimeStamp=06-03-08::10::04:37
(1) CREATE TABLE STATEMENT CHOOSE
Est. Rows: 274 Cost: 68,076
LOAD AS SELECT
(14) CONCATENATION
(4) HASH JOIN
Est. Rows: 1 Cost: 17,019
(2) UNIQUE INDEX FAST FULL SCAN SC2.IMP_TMP_GLOBAL__NAME [Not Analyzed]
Est. Rows: 146,873 Cost: 15
(3) TABLE ACCESS FULL SC1.BA_DISP_XX [Analyzed]
Blocks: 2,436 Est. Rows: 32 of 31,951 Cost: 17,004
(7) HASH JOIN
Est. Rows: 1 Cost: 17,019
(5) UNIQUE INDEX FAST FULL SCAN SC2.IMP_TMP_GLOBAL _NAME  [Not Analyzed]
Est. Rows: 146,873 Cost: 15
(6) TABLE ACCESS FULL SC1.BA_DISP_XX [Analyzed]
Blocks: 2,436 Est. Rows: 32 of 31,951 Cost: 17,004
(10) HASH JOIN
Est. Rows: 1 Cost: 17,019
(8) UNIQUE INDEX FAST FULL SCAN SC2.IMP_TMP_GLOBAL__NAME [Not Analyzed]
Est. Rows: 146,873 Cost: 15
(9) TABLE ACCESS FULL SC1.BA_DISP_XX [Analyzed]
Blocks: 2,436 Est. Rows: 32 of 31,951 Cost: 17,004
(13) HASH JOIN
Est. Rows: 1 Cost: 17,019
(11) UNIQUE INDEX FAST FULL SCAN SC2.IMP_TMP_GLOBAL _NAME  [Not Analyzed]
Est. Rows: 146,873 Cost: 15
(12) TABLE ACCESS FULL SC1.BA_DISP_XX [Analyzed]
Blocks: 2,436 Est. Rows: 32 of 31,951 Cost: 17,004
- Mahesh

First, can you repost with better formatting. Your execution plan has lost any indentation, and everything is at the same level, which makes it difficult to work out the real order of execution. Put the SQL statement and plan between lines with and on them, but with CODE in lower case i.e. code, which the forum engine recognises.
Second, you seem to have four full table scans on ba_DISP_XX, which is probably due to the IN clause in the WHERE. I don't know what indexes you have, because you don't mention it. But Oracle cannot use ordinary indexes on columns when you apply a function or expression to that column. Which is what you are doing to the dsp_hash column, with the TRUNC function.
So, the quickest comments I can make are:
Investigate using function based indexes, but you may need several of them, which all take up disk space.
Rewrite the query to not use TRUNC, or to use it in a standard way so that a single function based index could be used.
Get rid of the hints. You are explicitly telling Oracle to use a HASH join, and PARALLEL scan the ba_DISP_XX table. Which is what it is doing in the execution plan. So you are getting what you have asked for.
The query is very odd. Where is the proper join between tables x and d? I see an IN between them, which is unlikely to be the join. And a LOWER LIKE. If this is the join, then create a function based index on LOWER (d.url_name). Again, without a suitable index, Oracle will scan the full table.
Bottom line - the query is doing what you want, because you have used hints to tell it to scan that table and use a HASH join, and without using function based indexes Oracle cannot used ordinary indexes for this query. So it will table scan either way.
John

Similar Messages

  • Can anyone plz tell me the steps for performance tuning.

    hello friends
    what is performance tuning?
    can anyone plz tell me the steps for performance tuning.

    Hi Kishore, this will help u.
    Following are the different tools provided by SAP for performance analysis of an ABAP object
    Run time analysis transaction SE30
    This transaction gives all the analysis of an ABAP program with respect to the database and the non-database processing.
    SQL Trace transaction ST05
    The trace list has many lines that are not related to the SELECT statement in the ABAP program. This is because the execution of any ABAP program requires additional administrative SQL calls. To restrict the list output, use the filter introducing the trace list.
    The trace list contains different SQL statements simultaneously related to the one SELECT statement in the ABAP program. This is because the R/3 Database Interface - a sophisticated component of the R/3 Application Server - maps every Open SQL statement to one or a series of physical database calls and brings it to execution. This mapping, crucial to R/3s performance, depends on the particular call and database system. For example, the SELECT-ENDSELECT loop on the SPFLI table in our test program is mapped to a sequence PREPARE-OPEN-FETCH of physical calls in an Oracle environment.
    The WHERE clause in the trace list's SQL statement is different from the WHERE clause in the ABAP statement. This is because in an R/3 system, a client is a self-contained unit with separate master records and its own set of table data (in commercial, organizational, and technical terms). With ABAP, every Open SQL statement automatically executes within the correct client environment. For this reason, a condition with the actual client code is added to every WHERE clause if a client field is a component of the searched table.
    To see a statement's execution plan, just position the cursor on the PREPARE statement and choose Explain SQL. A detailed explanation of the execution plan depends on the database system in use.
    Need for performance tuning
    In this world of SAP programming, ABAP is the universal language. In most of the projects, the focus is on getting a team of ABAP programmers as soon as possible, handing over the technical specifications to them and asking them to churn out the ABAP programs within the “given deadlines”.
    Often due to this pressure of schedules and deliveries, the main focus of making a efficient program takes a back seat. An efficient ABAP program is one which delivers the required output to the user in a finite time as per the complexity of the program, rather than hearing the comment “I put the program to run, have my lunch and come back to check the results”.
    Leaving aside the hyperbole, a performance optimized ABAP program saves the time of the end user, thus increasing the productivity of the user, and in turn keeping the user and the management happy.
    This tutorial focuses on presenting various performance tuning tips and tricks to make the ABAP programs efficient in doing their work. This tutorial also assumes that the reader is well versed in all the concepts and syntax of ABAP programming.
    Use of selection criteria
    Instead of selecting all the data and doing the processing during the selection, it is advisable to restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code.
    Not recommended
    Select * from zflight.
    Check : zflight-airln = ‘LF’ and zflight-fligh = ‘BW222’.
    Endselect.
    Recommended
    Select * from zflight where airln = ‘LF’ and fligh = ‘222’.
    Endselect.
    One more point to be noted here is of the select *. Often this is a lazy coding practice. When a programmer gives select * even if one or two fields are to be selected, this can significantly slow the program and put unnecessary load on the entire system. When the application server sends this request to the database server, and the database server has to pass on the entire structure for each row back to the application server. This consumes both CPU and networking resources, especially for large structures.
    Thus it is advisable to select only those fields that are needed, so that the database server passes only a small amount of data back.
    Also it is advisable to avoid selecting the data fields into local variables as this also puts unnecessary load on the server. Instead attempt must be made to select the fields into an internal table.
    Use of aggregate functions
    Use the already provided aggregate functions, instead of finding out the minimum/maximum values using ABAP code.
    Not recommended
    Maxnu = 0.
    Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.
    Check zflight-fligh > maxnu.
    Maxnu = zflight-fligh.
    Endselect.
    Recommended
    Select max( fligh ) from zflight into maxnu where airln = ‘LF’ and cntry = ‘IN’.
    The other aggregate functions that can be used are min (to find the minimum value), avg (to find the average of a Data interval), sum (to add up a data interval) and count (counting the lines in a data selection).
    Use of Views instead of base tables
    Many times ABAP programmers deal with base tables and nested selects. Instead it is always advisable to see whether there is any view provided by SAP on those base tables, so that the data can be filtered out directly, rather than specially coding for it.
    Not recommended
    Select * from zcntry where cntry like ‘IN%’.
    Select single * from zflight where cntry = zcntry-cntry and airln = ‘LF’.
    Endselect.
    Recommended
    Select * from zcnfl where cntry like ‘IN%’ and airln = ‘LF’.
    Endselect.
    Check this links
    http://www.sapdevelopment.co.uk/perform/performhome.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/afbad390-0201-0010-daa4-9ef0168d41b6
    kindly reward if found helpful.
    cheers,
    Hema.

  • Can anyone send tutor for performance tuning?

    can anyone send tutor for performance tuning?I like to chk my coding.

    1.      Unused/Dead code
    Avoid leaving unused code in the program. Either comment out or delete the unused situation. Use program --> check --> extended program to check for the variables, which are not used statically. 
    2.      Subroutine Usage
    For good modularization, the decision of whether or not to execute a subroutine should be made before the subroutine is called. For example:  
    This is better:
    IF f1 NE 0.
      PERFORM sub1.
    ENDIF. 
    FORM sub1.
    ENDFORM.  
    Than this:
    PERFORM sub1.
    FORM sub1.
      IF f1 NE 0.
      ENDIF.
    ENDFORM. 
    3.      Usage of IF statements
    When coding IF tests, nest the testing conditions so that the outer conditions are those which are most likely to fail. For logical expressions with AND , place the mostly likely false first and for the OR, place the mostly likely true first. 
    Example - nested IF's:
      IF (least likely to be true).
        IF (less likely to be true).
         IF (most likely to be true).
         ENDIF.
        ENDIF.
       ENDIF. 
    Example - IF...ELSEIF...ENDIF :
      IF (most likely to be true).
      ELSEIF (less likely to be true).
      ELSEIF (least likely to be true).
      ENDIF. 
    Example - AND:
       IF (least likely to be true) AND
          (most likely to be true).
       ENDIF.
    Example - OR:
            IF (most likely to be true) OR
          (least likely to be true). 
    4.      CASE vs. nested Ifs
    When testing fields "equal to" something, one can use either the nested IF or the CASE statement. The CASE is better for two reasons. It is easier to read and after about five nested IFs the performance of the CASE is more efficient. 
    5.      MOVE statements
    When records a and b have the exact same structure, it is more efficient to MOVE a TO b than to  MOVE-CORRESPONDING a TO b.
    MOVE BSEG TO *BSEG.
    is better than
    MOVE-CORRESPONDING BSEG TO *BSEG. 
    6.      SELECT and SELECT SINGLE
    When using the SELECT statement, study the key and always provide as much of the left-most part of the key as possible. If the entire key can be qualified, code a SELECT SINGLE not just a SELECT.   If you are only interested in the first row or there is only one row to be returned, using SELECT SINGLE can increase performance by up to three times. 
    7.      Small internal tables vs. complete internal tables
    In general it is better to minimize the number of fields declared in an internal table.  While it may be convenient to declare an internal table using the LIKE command, in most cases, programs will not use all fields in the SAP standard table.
    For example:
    Instead of this:
    data:  t_mara like mara occurs 0 with header line.
    Use this:
    data: begin of t_mara occurs 0,
            matnr like mara-matnr,
            end of t_mara. 
    8.      Row-level processing and SELECT SINGLE
    Similar to the processing of a SELECT-ENDSELECT loop, when calling multiple SELECT-SINGLE commands on a non-buffered table (check Data Dictionary -> Technical Info), you should do the following to improve performance:
    o       Use the SELECT into <itab> to buffer the necessary rows in an internal table, then
    o       sort the rows by the key fields, then
    o       use a READ TABLE WITH KEY ... BINARY SEARCH in place of the SELECT SINGLE command. Note that this only make sense when the table you are buffering is not too large (this decision must be made on a case by case basis).
    9.      READing single records of internal tables
    When reading a single record in an internal table, the READ TABLE WITH KEY is not a direct READ.  This means that if the data is not sorted according to the key, the system must sequentially read the table.   Therefore, you should:
    o       SORT the table
    o       use READ TABLE WITH KEY BINARY SEARCH for better performance. 
    10.  SORTing internal tables
    When SORTing internal tables, specify the fields to SORTed.
    SORT ITAB BY FLD1 FLD2.
    is more efficient than
    SORT ITAB.  
    11.  Number of entries in an internal table
    To find out how many entries are in an internal table use DESCRIBE.
    DESCRIBE TABLE ITAB LINES CNTLNS.
    is more efficient than
    LOOP AT ITAB.
      CNTLNS = CNTLNS + 1.
    ENDLOOP. 
    12.  Performance diagnosis
    To diagnose performance problems, it is recommended to use the SAP transaction SE30, ABAP/4 Runtime Analysis. The utility allows statistical analysis of transactions and programs. 
    13.  Nested SELECTs versus table views
    Since releASE 4.0, OPEN SQL allows both inner and outer table joins.  A nested SELECT loop may be used to accomplish the same concept.  However, the performance of nested SELECT loops is very poor in comparison to a join.  Hence, to improve performance by a factor of 25x and reduce network load, you should either create a view in the data dictionary then use this view to select data, or code the select using a join. 
    14.  If nested SELECTs must be used
    As mentioned previously, performance can be dramatically improved by using views instead of nested SELECTs, however, if this is not possible, then the following example of using an internal table in a nested SELECT can also improve performance by a factor of 5x:
    Use this:
    form select_good.
      data: t_vbak like vbak occurs 0 with header line.
      data: t_vbap like vbap occurs 0 with header line.
      select * from vbak into table t_vbak up to 200 rows.
      select * from vbap
              for all entries in t_vbak
              where vbeln = t_vbak-vbeln.
      endselect.
    endform.
    Instead of this:
    form select_bad.
    select * from vbak up to 200 rows.
      select * from vbap where vbeln = vbak-vbeln.
      endselect.
    endselect.
    endform.
    Although using "SELECT...FOR ALL ENTRIES IN..." is generally very fast, you should be aware of the three pitfalls of using it:
    Firstly, SAP automatically removes any duplicates from the rest of the retrieved records.  Therefore, if you wish to ensure that no qualifying records are discarded, the field list of the inner SELECT must be designed to ensure the retrieved records will contain no duplicates (normally, this would mean including in the list of retrieved fields all of those fields that comprise that table's primary key).
    Secondly,  if you were able to code "SELECT ... FROM <database table> FOR ALL ENTRIES IN TABLE <itab>" and the internal table <itab> is empty, then all rows from <database table> will be retrieved.
    Thirdly, if the internal table supplying the selection criteria (i.e. internal table <itab> in the example "...FOR ALL ENTRIES IN TABLE <itab> ") contains a large number of entries, performance degradation may occur.
    15.  SELECT * versus SELECTing individual fields
    In general, use a SELECT statement specifying a list of fields instead of a SELECT * to reduce network traffic and improve performance.  For tables with only a few fields the improvements may be minor, but many SAP tables contain more than 50 fields when the program needs only a few.  In the latter case, the performace gains can be substantial.  For example:
    Use:
    select vbeln auart vbtyp from table vbak
      into (vbak-vbeln, vbak-auart, vbak-vbtyp)
      where ...
    Instead of using:
    select * from vbak where ... 
    16.  Avoid unnecessary statements
    There are a few cases where one command is better than two.  For example:
    Use:
    append <tab_wa> to <tab>.
    Instead of:
    <tab> = <tab_wa>.
    append <tab> (modify <tab>).
    And also, use:
    if not <tab>[] is initial.
    Instead of:
    describe table <tab> lines <line_counter>.
    if <line_counter> > 0. 
    17.  Copying or appending internal tables
    Use this:
    <tab2>[] = <tab1>[].  (if <tab2> is empty)
    Instead of this:
    loop at <tab1>.
      append <tab1> to <tab2>.
    endloop.
    However, if <tab2> is not empty and should not be overwritten, then use:
    append lines of <tab1> [from index1] [to index2] to <tab2>.
    P.S : Please reward if you find this useful..

  • Resources for performance tuning and RAC needed

    Can you suggest me the best knowledge resources for performance tuning and RAC?
    Besides Oracle doc ...
    Thanks!

    Before all, I'm searching for resources on web like performance tuning from Dizwell Informatics is.
    Anyway thank you Eric for your suggestion!

  • Steps for performance Tuning....!!!!

    Hi all,
    I need your help in Performance tuning.
    While we do tuning in Oracle, apart from Indexes, where clause and order by clause, what are the other points we need to check. I mean explain plan etc...
    I am working as Informatica Developer, but i need to make an documents which points out what are the step we can check while doing performance tuning on SQL queries.
    Thanks in advance for your help.

    Hi,
    have a look into these link.it may helpful to you.
    When your query takes too long .
    When your query takes too long ...
    * HOW TO Post a SQL statement tuning request template posting *
    HOW TO: Post a SQL statement tuning request - template posting
    Edited by: Ravi291283 on Jul 28, 2009 4:00 AM
    Edited by: Ravi291283 on Jul 28, 2009 4:01 AM
    Edited by: Ravi291283 on Jul 28, 2009 4:02 AM

  • Privilleges for performance tuning

    can we assign any specific privilleges to DBA for the performance tuning.
    i dont want to give sysdba and sysopr privilleges to DBA.

    The question should be why there is need to tune anything in Oracle database. What is the problem, have you defined the problem in a very clear manner ?  Is there anything which is called problem or it is something other one ?  What performance tuning tool you are going to use and why ?
    Performance tuning is only two words, but it is very big topic; a topic on which 100 books / blogs have been written and still writing going on.
    What and why are you trying to tune and what ORA you got ? As such there is no ready made role in oracle which says something like "PT_ROLE".  We just issue the sql to the dictionary objects and as and when we gets privileges related error, we provides select on those sys objects to user; if he really needs though.
    Regards
    Girish Sharma

  • Query About performance tuning

    Hi Guru's
    May be this question is stupid one, but i think this is the forum where every user get details of all there questions.
    I want to start learning Performance tuning but not know the path from where to start can anyone suggest me the same.
    Thanks in advance

    Hi,
    performance tuning is a huge area. It involves following skills:
    1. Understanding how Oracle stores data (physical structure of tables and indexes) and how it reads and writes it.
    2. Understanding how Oracle processes and executes queries
    3. Ability to read execution plans (not just scan them for 'red flags')
    4. Familiarity is most common wait events, knowing and understanding Oracle Wait Interface and its limitations
    5. Ability to understand AWR and ASH data and its limitations
    6. Understanding Oracle optimizer and it's inputs, knowing basic formulas for cardinality and selectivity, cardinality feedback tuning
    7. Abilty to read trace files (first of all extended SQL trace, 10046, and CBO trace, 10053)
    8. Understanding concurrency and read consistency and work Oracle does to maintain them.
    This is probably not a complete list. Of course you won't be able to learn everything at once. You can start by reading:
    1. The official Oracle Performance Tuning Guide
    2. T. Kyte's books on Oracle architecture
    3. Milsap's and Holt's book "Optimizing Oracle Performance"
    4. J. Lewis "Cost based fundamentals"
    Best regards,
    Nikolay

  • Abap Logic for performance tuning not working when using Internal tables

    Hi,
    I wrote this piece of code that is working correctly that is select SUM of cost from DSO where Plant is the same for Sales Items.
    LOOP AT RESULT_PACKAGE INTO rp.
    SELECT SUM( /N/S_STRDCOST ) FROM /N/ADSP_DPIT00 INTO
    rp-/N/S_STRDCOST
    WHERE /N42/S_SALESITEM = rp-/N42/S_ITEMID AND /N42/S_PLPLANT EQ
    rp-/N42/S_SOURCE.
    MODIFY RESULT_PACKAGE FROM rp.
    Clear rp.
    ENDLOOP.
    Now I try to rewrite it for performance tunning using internal table  but I am getting 0 values. can't figure out whats the problem and been struggling fixing it.
    TYPES : begin of ty_DSO_TABLE,
             /N42/S_STRDCOST TYPE /N/ADSP_DSPC00-/N/S_STRDCOST,
             /N42/S_ITEMID TYPE /N/ADSP_DSPC00-/N/S_ITEMID,
           end of ty_DSO_TABLE.
    DATA: it_DSO_TABLE type hashed table of ty_DSO_TABLE with unique key
    /N/S_ITEMID,
         wa_DSO_TABLE type ty_DSO_TABLE.
    Field-symbols:  <rp> TYPE tys_TG_1.
    LOOP AT RESULT_PACKAGE assigning <rp>.
      clear wa_DSO_TABLE.
    Read table IT_DSO_TABLE into wa_DSO_TABLE with table key /N/S_ITEMID
      = <rp>-/N/S_ITEMID.
      if sy-subrc ne 0.
          select SUM( /N/S_STRDCOST )  into CORRESPONDING
          FIELDS OF wa_DSO_TABLE from
          /N/ADSP_DPIT00 WHERE /N/S_SALESITEM =  <rp>-/N/S_ITEMID AND
          /N/S_PLPLANT EQ <rp>-/N/S_SOURCE.
         if sy-subrc eq 0.
              <rp>-/N/S_STRDCOST = wa_DSO_TABLE-/N/S_STRDCOST.
         endif.
    endif.
    ENDLOOP.
    Any idea whats wrong with the code
    thanks

    Hi Vaidya,
    According to the code which you have written, there is no value in table IT_DSO_TABLE when you are trying to read the values.And after the read statement you have given a condition for sy-subrc. Hence the select statement is actually not even getting executed. *Also you have not assigned the final value back to the ResultPackage.*_
    So Kindly correct your code as follows:
    Data: wa_dso type ty_DSO_TABLE.
    LOOP AT RESULT_PACKAGE assigning <rp>.
    clear wa_DSO_TABLE.
    select SUM( /N/S_STRDCOST ) into CORRESPONDING
    FIELDS OF wa_DSO_TABLE from
    /N/ADSP_DPIT00 WHERE /N/S_SALESITEM = <rp>-/N/S_ITEMID AND
    /N/S_PLPLANT EQ <rp>-/N/S_SOURCE.
    if sy-subrc eq 0.
    <rp>-/N/S_STRDCOST = wa_DSO_TABLE-/N/S_STRDCOST.
    MODIFY RESULT_PACKAGE FROM <rp>.
    endif.
    ENDLOOP.
    Hope this helps you.
    Regards,
    Satyam

  • Step for performance tuning in oracle 10g

    hi,
    i want to know the step of persformance tuning and sql tuning.

    I'd suggest you to refer to documentation: [Oracle Database 2 Day + Performance Tuning Guide 10g Release 2 (10.2)|http://download.oracle.com/docs/cd/B19306_01/server.102/b28051/toc.htm]
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com
    [Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]

  • How to use forms trace file for performance tuning

    I am trying to use forms trace file in order to find cause of forms application performance problem.
    I have read the document B14032-03 where is described how to turn on tracing and how to convert binary trace file to xml or html format. However these xml/html files are useless because they only contain series of forms events, without possibility for grouping or sorting. Actually, they are like to database raw trace file. I need some tool, like tkprof for database trace, that will process xml/html file and generate some more useful format.
    Further, I have tried to load forms trace file into relational database tables in order to use SQL for performance problem investigation. I have followed procedure described in document A92175-01, but without success.
    Is there any way to process xml/html file with grouping, orderering or summing event duration or way to load either binary, xml or html trace file into structured data in database.

    Al-Salamu Alikum user630033
    It's not : elegant at all to thank people 4 No help,it's not their problem that u don't search enough, or u don't have access to db.
    We should always say thank ,or 'Jazak Allah Khiern' on both cases even they could or couldn't help u.
    Finally,i expect ' an appologize or even a thankful word ' and the kindness i am sure u had to publish the solution u found in order to share it with people who had same problem or at least to give them the info to get the appreciation or the thanksful word u deserve.
    Rem.Never give a bad feedback to people who tried to help u.
    Regards,
    Abdetu..

  • Need guidance on Query for fine Tuning

    Hi ,
    Please help me on the below query while rewriting. Actually it is taking 2.56 sec to give 2.25 lacs records.
    I am trying to tune this query since 2 days,but not able to understand where to change & why it is taking that much time.
    Using : Oracle 10g version
    Tool : TOAD 8.6.1
    There are Indexes on every column used in Where clause but still some table scanning full.
    becoz of Inner Join it is taking much time, So Can anyone rewrite the below query for faster execution.
    SELECT workorder.fincode,
         workorder.istask,
         workorder.status,
    workorder.targstartdate,
         workorder.targcompdate,
         workorder.schedfinish,
    workorder.actfinish,
         workorder.estdur,
         workorder.wonum,
         workorder.mprn,
    workorder.sihousename AS wositehousename,
    workorder.sihouseno AS wositehouseno,
    workorder.sistreet AS wositestreet,
         workorder.sicounty AS wositecounty,
    workorder.siposttown AS wositeposttown,
    workorder.sipostcode AS wositepostcode,
         workorder.workorderid
    FROM (maximo.sr
    INNER JOIN
    (maximo.relatedrecord INNER JOIN maximo.workorder
    ON relatedrecord.relatedreckey =
    (CASE
    WHEN workorder.PARENT IS NOT NULL
    THEN workorder.PARENT
    ELSE workorder.wonum
    END
    AND relatedrecord.orgid = workorder.orgid
    AND relatedrecord.siteid = workorder.siteid
    AND relatedrecord.relatedrecclass = 'WORKORDER')
    ON sr.ticketid = relatedrecord.recordkey
    AND sr.orgid = relatedrecord.orgid
    AND sr.siteid = relatedrecord.siteid
    AND relatedrecord.CLASS = 'SR')
    LEFT JOIN
    frozen_quote@gqmfof
    ON sr.ticketid = customer_enquiry_ref AND sr.quotever = quote_version
    Explan Result:
    PLAN_TABLE_OUTPUT
    Plan hash value: 599875212
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Inst |IN-OUT|
    | 0 | SELECT STATEMENT | | 1569 | 272K| 3362 (1)| 00:00:41 | | |
    |* 1 | HASH JOIN | | 1569 | 272K| 3362 (1)| 00:00:41 | | |
    |* 2 | HASH JOIN RIGHT OUTER | | 1263 | 92199 | 417 (4)| 00:00:06 | | |
    | 3 | REMOTE | | 1 | 10 | 2 (0)| 00:00:01 | GQMFOF | R->S |
    | 4 | NESTED LOOPS | | 1263 | 79569 | 414 (3)| 00:00:05 | | |
    | 5 | MERGE JOIN CARTESIAN | | 3798 | 159K| 397 (3)| 00:00:05 | | |
    | 6 | VIEW | VW_NSO_1 | 1 | 14 | 3 (34)| 00:00:01 | | |
    | 7 | SORT UNIQUE | | 1 | 26 | 3 (34)| 00:00:01 | | |
    |* 8 | INDEX RANGE SCAN | SYNONYMDOM_NDX1 | 1 | 26 | 2 (0)| 00:00:01 | | |
    | 9 | BUFFER SORT | | 3798 | 107K| 397 (3)| 00:00:05 | | |
    |* 10 | TABLE ACCESS FULL | RELATEDRECORD | 3798 | 107K| 394 (3)| 00:00:05 | | |
    |* 11 | TABLE ACCESS BY INDEX ROWID| TICKET | 1 | 20 | 1 (0)| 00:00:01 | | |
    |* 12 | INDEX UNIQUE SCAN | TICKET_NDX1 | 1 | | 0 (0)| 00:00:01 | | |
    | 13 | TABLE ACCESS FULL | WORKORDER | 231K| 23M| 2943 (1)| 00:00:36 | | |
    Predicate Information (identified by operation id):
    1 - access("RELATEDRECORD"."RELATEDRECKEY"=CASE WHEN ("WORKORDER"."PARENT" IS NOT NULL) THEN
    "WORKORDER"."PARENT" ELSE "WORKORDER"."WONUM" END AND "RELATEDRECORD"."ORGID"="WORKORDER"."ORGID" AND
    "RELATEDRECORD"."SITEID"="WORKORDER"."SITEID")
    2 - access("TICKET"."QUOTEVER"="QUOTE_VERSION"(+) AND "TICKET"."TICKETID"="CUSTOMER_ENQUIRY_REF"(+))
    8 - access("DOMAINID"='TKCLASS' AND "MAXVALUE"='SR')
    10 - filter("RELATEDRECORD"."CLASS"='SR' AND "RELATEDRECORD"."RELATEDRECCLASS"='WORKORDER')
    11 - filter("TICKET"."ORGID"="RELATEDRECORD"."ORGID" AND "TICKET"."SITEID"="RELATEDRECORD"."SITEID")
    12 - access("CLASS"="$nso_col_1" AND "TICKET"."TICKETID"="RELATEDRECORD"."RECORDKEY")
    Regards,
    GR

    Add the NOCYCLE clause to your connect by statement CONNECT BY NOCYCLE PRIOR
    You also might want to add the organization ID into your join.

  • Report Slow Due to Mass Data , Soln for Performance Tuning

    Dear All,
    I am making report with mass data so for this i have to put For All enteries in & Ranges at lodz of places.
    1. For all enteries in is making my report works very slow.
    2. If i change for all enteries by Ranges then if the no. of records are large the system will thn
        throw dump.
    If the no. of records are large or the logic applied in complex then report is taking very long
    execution time , Can anyone suggest me the method by which i can optimize my report and make it
    run smoother in performance.
    Thanks
    Ankesh Jindal

    Hi,
    >
    Ankesh Jindal wrote:
    > The problem is with FAE and ranges acc to uptill i have discovered,
    > As I have mentioned if I take FAE and number of records are large the execution will take
    > very large amount of time for that i have changed FAE to ranges but still if no. of records are
    > large in ranges system will throw dump
    >
    so far so good. SQL statements must not get too large.
    >
    Ankesh Jindal wrote:
    > so the best soln for this which i have considered for
    > my reports is to use ranges but with some logic applied that is ;
    >  suppose i have 20,000 records then send data to ranges in 3k or 4k lots .
    > so in this case i am using ranges with 3k or 4k lots so the sytem will not throw dump and i will get
    > faster execution of query with ranges...
    >
    General question: How big is the runtime difference for your SELECT with Range (4k) and the default FAE (5 in case of ORACLE)... more than 20%? could you post your actual run time figures?
    Your range approach is faster because you do less database calls. 5 db calls if you have 4 k entries in the range.
    You can influence the number of database calls as well for the FAE.
    Assuming you are running on ORACLE with a default configuration you have 5 entries per call.
    (Parameters rsdb/max_in_blocking_factor, rsdb/max_blocking_factor). So you will end up
    with 4000 db calls with 5 records each. 
    You compare that with 5 db calls with 4000 records for your range... this is not fair
    Hint your FAE with this, this would lead to 5 db calls for the FAE as well.:
        %_hints oracle '&max_in_blocking_factor 4000&'.
    now compare again... .
    Note1: Be care full with big ranges and blocking factors... cost based optimizers may react sensitive to big inlists or or concatenations and may change plans suddenly... .
    Note2: If you are not on ORACLE your blocking factors may be considerably higher (30, 60, ...).
    Kind regards,
    Hermann

  • Pls help me to modify the query for performance improvement

    Hi,
    I have the below initialization
    DECLARE @Active bit =1 ;
    Declare @id int
    SELECT @Active=CASE WHEN id=@id and [Rank] ='Good' then 0 else 1 END  FROM dbo.Students
    I have to change this query in such a way that the conditions id=@id and [Rank] ='Good' should go to the where condition of the query. In that case, how can i use Case statement to retrieve 1 or 0? Can you please help me to modify this initialization?

    I dont understand your query...May be below? or provide us sample data and your output...
    SELECT *  FROM dbo.students
    where @Active=CASE
    WHEN id=@id and rank ='Good' then 0 else 1 END
    But, I doubt you will have performance improvement here?
    Do you have index on id?
    If you are looking for getting the data for @ID with rank ='Good' then use the below:Make sure, you have index on id,rank combination.
    SELECT *  FROM dbo.students
    where  id=@id
    and rank ='Good' 

  • Please review procedure for performance tuning

    Hi Friends,
    I have a procedure, which is taking lot of time for execution. Please help me how can i tune this procedure to reduce the execution time.
    Purpose of the procedure : This procedure runs every data to load data from DWH to Data Marts,
    We have some adverse keywords given by business in the table CFG_ADVERSE_KEYWORD ,the procedure will identify the keywords in the tables like df_call_ae_vd, in the notes column and loads only records which has adverse keywords.
    Below is the procedure
    create or replace procedure              LOAD_DM_AE_DATA_PRC
    as
    v_insert_count              NUMBER  := 0;
    /* current_process identifies the block of code where exception is raised, used for debugging */
    v_current_process           VARCHAR2(100) := NULL;
    v_error_code                VARCHAR2(8)   := NULL;
    v_error_text                VARCHAR2(110) := NULL;
    v_error_msg                 VARCHAR2(500) := NULL;
    v_error_count               NUMBER  := 0;
    /* module_name is the procedure name */
    v_module_name               VARCHAR2(50)  := 'LOAD_DM_AE_DATA_PRC';
    /* table_name is the target table truncated and loaded by the procedure */
    v_table_name                 VARCHAR2(50)  := NULL;
    v_table_name1                VARCHAR2(50)  := 'MM_USER_AE_VD';
    v_table_name2                VARCHAR2(50)  := 'MF_CALL_AE_VD';
    v_table_name3                VARCHAR2(50)  := 'MM_CHANGE_REQUEST_AE_VD';
    v_table_name4                VARCHAR2(50)  := 'MM_COMPETITOR_INSIGHT_AE_VD';
    v_table_name5                VARCHAR2(50)  := 'MM_FORMULARY_AE_VD';
    v_table_name6                VARCHAR2(50)  := 'MM_MED_INQUIRY_AE_VD';
    v_table_name7                VARCHAR2(50)  := 'MM_SAMPLETRANS_AE_VD';
    v_table_name8                VARCHAR2(50)  := 'MM_ADVERSE_EVENT_ALL';
    v_table_name9                VARCHAR2(50)  := 'MM_USER_COUNTRY_AE_VD';
    v_table_name10               VARCHAR2(50)  := 'CFG_AE_CONCAT_KEYWORD';
    v_table_name                 VARCHAR2(50)  := NULL;
    /* source_name is the view or source table */
    v_source_name                VARCHAR2(50)  := 'DA_RDW_AP_DWH';
    /* Variables specific to application.  */
    ** Declare Exceptions                                                                          *
    procedure_err              EXCEPTION;
    ** Begin procedure                                                                             *
    BEGIN /* procedure*/
      DBMS_OUTPUT.ENABLE(1000000);
    ** Truncate tables                                                                             *
      BEGIN /* Truncate target*/
        v_current_process := 'Truncate table ' || v_table_name1;
        DBMS_OUTPUT.PUT_LINE(v_current_process);
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name1);              
        DBMS_OUTPUT.PUT_LINE (v_table_name1||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name2);              
        DBMS_OUTPUT.PUT_LINE (v_table_name2||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name3);              
        DBMS_OUTPUT.PUT_LINE (v_table_name3||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name4);              
        DBMS_OUTPUT.PUT_LINE (v_table_name4||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name5);              
        DBMS_OUTPUT.PUT_LINE (v_table_name5||' truncated' );
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name6);              
        DBMS_OUTPUT.PUT_LINE (v_table_name6||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name7);              
        DBMS_OUTPUT.PUT_LINE (v_table_name7||' truncated' ); 
       EXECUTE IMMEDIATE ('Truncate table ' || v_table_name8);              
        DBMS_OUTPUT.PUT_LINE (v_table_name8||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name9);              
        DBMS_OUTPUT.PUT_LINE (v_table_name9||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name10);              
        DBMS_OUTPUT.PUT_LINE (v_table_name10||' truncated' ); 
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END; /* Truncate target*/
    ** 1.Load table MM_USER_AE_VD                                                                  *
       BEGIN  
        insert into DM_RDW_AP_VD.MM_USER_AE_VD
        ( ID                     ,
          NAME                   ,
          COUNTRY_CODE_BI__C     ,
          LASTMODIFIEDDATE       ,
          SYSTEMMODSTAMP )
        select
          ID                     ,
          NAME                   ,
          COUNTRY_CODE_BI__C     ,
          LASTMODIFIEDDATE       ,
          sysdate
        from DA_RDW_AP.DM_USER_AE_VD
        union
        select '999', 'Do not delete this record', null, sysdate-1, sysdate-1
        from dual;
        DBMS_OUTPUT.PUT_LINE (v_table_name1||' - '||SQL%ROWCOUNT||' records loaded' ); 
        commit;
       EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
       END;
    ** 2. SCAN/Load table MF_CALL_AE_VD                                                            *
      BEGIN  
           insert into DM_RDW_AP_VD.MF_CALL_AE_VD
            ( ID                      ,
              NAME                    ,
              CALL_DATE_VOD__C        ,
              PRE_CALL_NOTES_VOD__C   ,
              NEXT_CALL_NOTES_VOD__C  ,
       NEXT_CALL_NOTES_VOD__C_HTML,
              COUNTRY_CODE_BI__C      ,
              OWNERID                 ,
              LASTMODIFIEDDATE        ,
              SYSTEMMODSTAMP)
      select
              distinct a.ID             ,
              a.NAME                    ,
              a.CALL_DATE_VOD__C        ,
              a.PRE_CALL_NOTES_VOD__C   ,
              a.NEXT_CALL_NOTES_VOD__C  ,
       replace(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '),
        substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '), instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C), chr(10),' '), chr(13), ''), lower(   trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '), instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
      ) as NEXT_CALL_NOTES_VOD__C_HTML,
              a.COUNTRY_CODE_BI__C      ,
              a.OWNERID                 ,
              a.LASTMODIFIEDDATE        ,
              a.SYSTEMMODSTAMP
          from (da_rdw_ap.df_call_ae_vd a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          --where  (b.country_code = 'EN' and instr( lower(a.NEXT_CALL_NOTES_VOD__C), lower(b.Keyword) , 1, 1 ) > 0)
        where  (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and a.NEXT_CALL_NOTES_VOD__C is not null
          union
       select
              distinct a.ID             ,
              a.NAME                    ,
              a.CALL_DATE_VOD__C        ,
              a.PRE_CALL_NOTES_VOD__C   ,
              a.NEXT_CALL_NOTES_VOD__C  ,
       replace(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '),
               substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '), instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '), instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
              ) as NEXT_CALL_NOTES_VOD__C_HTML,
              a.COUNTRY_CODE_BI__C      ,
              a.OWNERID                 ,
              a.LASTMODIFIEDDATE        ,
              a.SYSTEMMODSTAMP         
          from (da_rdw_ap.df_call_ae_vd a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
       --where (instr( lower(a.NEXT_CALL_NOTES_VOD__C), lower(b.Keyword) , 1, 1 ) > 0 );
          where (instr( lower(' ' || translate(trim(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0)  and  b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name2||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
         EXCEPTION
            WHEN OTHERS THEN
              v_error_count := v_error_count + 1;
              v_error_code  := TO_CHAR(sqlcode);
              v_error_text  := SUBSTR(sqlerrm, 1, 110);
              RAISE procedure_err;
      END;
    ** 3. SCAN/Load table MM_CHANGE_REQUEST_AE_VD                                                  *
      BEGIN
        insert into DM_RDW_AP_VD.MM_CHANGE_REQUEST_AE_VD
          (   ID                      ,
              NAME                    ,
              COMMENTS_BI__C          ,
       COMMENTS_BI__C_HTML     ,
              COUNTRY_CODE_BI__C      ,
              OWNERID                 ,
              LASTMODIFIEDDATE        ,
              SYSTEMMODSTAMP )
          select
              distinct a.ID           ,
              a.NAME                  ,
              a.COMMENTS_BI__C        ,
       replace(replace(a.COMMENTS_BI__C, chr(10),' '),
               substr(replace(a.COMMENTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
              ) as COMMENTS_BI__C_HTML,
              a.COUNTRY_CODE_BI__C    ,
              a.OWNERID               ,
              a.LASTMODIFIEDDATE      ,
              a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_CHANGE_REQUEST_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          --where (b.country_code = 'EN' and instr( lower(a.COMMENTS_BI__C), lower(b.Keyword) , 1, 1 ) > 0) and a.COMMENTS_BI__C  is not null
       where (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.COMMENTS_BI__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and a.COMMENTS_BI__C is not null
          union
          select
              distinct a.ID           ,
              a.NAME                  ,
              a.COMMENTS_BI__C        ,
       replace(replace(a.COMMENTS_BI__C, chr(10),' '),
               substr(replace(a.COMMENTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
              ) as COMMENTS_BI__C_HTML,
              a.COUNTRY_CODE_BI__C    ,
              a.OWNERID               ,
              a.LASTMODIFIEDDATE      ,
              a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_CHANGE_REQUEST_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
          --where instr( lower(a.COMMENTS_BI__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMMENTS_BI__C  is not null;
       where (instr( lower(' ' || translate(trim(replace(a.COMMENTS_BI__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name3||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END;
    ** 4. SCAN/Load table MM_COMPETITOR_INSIGHT_AE_VD                                              *
      BEGIN
        insert into DM_RDW_AP_VD.MM_COMPETITOR_INSIGHT_AE_VD
         (  COMPETITOR_INSIGHTS_BI__C    ,
      COMPETITOR_INSIGHTS_BI__C_HTML,
            ID                           ,
            NAME                         ,
            OWNERID                      ,
            LASTMODIFIEDDATE             ,
            SYSTEMMODSTAMP )
          select
            distinct a.COMPETITOR_INSIGHTS_BI__C  ,
      replace(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '),
               substr(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMPETITOR_INSIGHTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMPETITOR_INSIGHTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
            ) as COMPETITOR_INSIGHTS_BI__C_HTML,
            a.ID                         ,
            a.NAME                       ,
            a.OWNERID                    ,
            a.LASTMODIFIEDDATE           ,
            a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_COMPETITOR_INSIGHT_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          --where (b.country_code = 'EN' and instr( lower(a.COMPETITOR_INSIGHTS_BI__C), lower(b.Keyword) , 1, 1 ) > 0) and a.COMPETITOR_INSIGHTS_BI__C is not null
       where (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0 ) and a.COMPETITOR_INSIGHTS_BI__C is not null
          union 
          select
            distinct a.COMPETITOR_INSIGHTS_BI__C  ,
      replace(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '),
             substr(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMPETITOR_INSIGHTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMPETITOR_INSIGHTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
            ) as COMPETITOR_INSIGHTS_BI__C_HTML,
            a.ID                         ,
            a.NAME                       ,
            a.OWNERID                    ,
            a.LASTMODIFIEDDATE           ,
            a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_COMPETITOR_INSIGHT_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
          --where instr( lower(a.COMPETITOR_INSIGHTS_BI__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMPETITOR_INSIGHTS_BI__C is not null;
       where (instr( lower(' ' || translate(trim(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name4||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END;
    ** 5. SCAN/Load table MM_FORMULARY_AE_VD                                                       *
      BEGIN
         insert into DM_RDW_AP_VD.MM_FORMULARY_AE_VD
          (    COMMENT_FORMULARY_BI__C   ,
        COMMENT_FORMULARY_BI__C_HTML,
               ID                        ,   
               NAME                      ,   
               OWNERID                   ,       
               LASTMODIFIEDDATE          ,
               SYSTEMMODSTAMP )
         select
               distinct  a. COMMENT_FORMULARY_BI__C,
        replace(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '),
                substr(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENT_FORMULARY_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                 '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENT_FORMULARY_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
               ) as COMMENT_FORMULARY_BI__C_HTML,
               a.ID                      ,
               a.NAME                    ,      
               a.OWNERID                 ,    
               a.LASTMODIFIEDDATE        ,
               a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_FORMULARY_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          -- where (b.country_code = 'EN' and instr( lower(a.COMMENT_FORMULARY_BI__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMMENT_FORMULARY_BI__C is not null)
         where (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.COMMENT_FORMULARY_BI__C , chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and a.COMMENT_FORMULARY_BI__C  is not null
          union
          select
               distinct  a. COMMENT_FORMULARY_BI__C,
            replace(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '),
                substr(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENT_FORMULARY_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                 '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENT_FORMULARY_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
               ) as COMMENT_FORMULARY_BI__C_HTML,
               a.ID                      ,
               a.NAME                    ,      
               a.OWNERID                 ,    
               a.LASTMODIFIEDDATE        ,
               a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_FORMULARY_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
          --where (instr( lower(a.COMMENT_FORMULARY_BI__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMMENT_FORMULARY_BI__C is not null);
       where (instr( lower(' ' || translate(trim(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1) > 0) and b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name5||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END;
    ** 6. SCAN/Load table MM_MED_INQUIRY_AE_VD                                                     *
      BEGIN
        insert into DM_RDW_AP_VD.MM_MED_INQUIRY_AE_VD
         (   ID                  ,
             NAME                ,
             INQUIRY_TEXT__C     ,
      INQUIRY_TEXT__C_HTML,
             CREATEDBYID         , 
             LASTMODIFIEDDATE    ,
             SYSTEMMODSTAMP )
           select
             distinct a.ID       ,
             a.NAME              ,
             a.INQUIRY_TEXT__C   ,
      replace(replace(a.INQUIRY_TEXT__C, chr(10),' '),
               substr(replace(a.INQUIRY_TEXT__C, chr(10),' '), instr(replace(replace(lower(a.INQUIRY_TEXT__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)),1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.INQUIRY_TEXT__C, chr(10),' '), instr(replace(replace(lower(a.INQUIRY_TEXT__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
             ) as INQUIRY_TEXT__C_HTML,
             a.CREATEDBYID       ,    
             a.LASTMODIFIEDDATE  ,
             a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_MED_INQUIRY_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.CREATEDBYID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          --where (b.country_code = 'EN' and instr( lower(a.INQUIRY_TEXT__C), lower(b.Keyword) , 1, 1 ) > 0 and a.INQUIRY_TEXT__C is not null)
       where (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.INQUIRY_TEXT__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and a.INQUIRY_TEXT__C  is not null
          union
          select
             distinct a.ID       ,
             a.NAME              ,
             a.INQUIRY_TEXT__C   ,
      replace(replace(a.INQUIRY_TEXT__C, chr(10),' '),
               substr(replace(a.INQUIRY_TEXT__C, chr(10),' '), instr(replace(replace(lower(a.INQUIRY_TEXT__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)),1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.INQUIRY_TEXT__C, chr(10),' '), instr(replace(replace(lower(a.INQUIRY_TEXT__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
             ) as INQUIRY_TEXT__C_HTML,
             a.CREATEDBYID       ,    
             a.LASTMODIFIEDDATE  ,
             a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_MED_INQUIRY_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.CREATEDBYID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
          --where (instr( lower(a.INQUIRY_TEXT__C), lower(b.Keyword) , 1, 1 ) > 0 and a.INQUIRY_TEXT__C is not null);
          where (instr( lower(' ' || translate(trim(replace(a.INQUIRY_TEXT__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name6||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END;
    ** 7. SCAN/Load table MM_SAMPLETRANS_AE_VD                                                     *
      BEGIN
        insert into DM_RDW_AP_VD.MM_SAMPLETRANS_AE_VD
         (  COMMENTS_VOD__C     ,
      COMMENTS_VOD__C_HTML,
            ID                  ,
            NAME                ,
            CREATEDBYID         ,
            LASTMODIFIEDDATE    ,
            SYSTEMMODSTAMP)
         select
            distinct  a.COMMENTS_VOD__C   ,
      replace(replace(a.COMMENTS_VOD__C, chr(10),' '),
             substr(replace(a.COMMENTS_VOD__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENTS_VOD__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
            ) as COMMENTS_VOD__C_HTML,
            a.ID                ,
            a.NAME              ,
            a.CREATEDBYID       ,   
            a.LASTMODIFIEDDATE  ,
            a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_SAMPLETRANS_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.CREATEDBYID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          --where (b.country_code = 'EN' and instr( lower(a.COMMENTS_VOD__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMMENTS_VOD__C is not null)
       where (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.COMMENTS_VOD__C , chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and a.COMMENTS_VOD__C  is not null
         union
         select
            a.COMMENTS_VOD__C   ,
      replace(replace(a.COMMENTS_VOD__C, chr(10),' '),
             substr(replace(a.COMMENTS_VOD__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENTS_VOD__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
            ) as COMMENTS_VOD__C_HTML,
            a.ID                ,
            a.NAME              ,
            a.CREATEDBYID       ,   
            a.LASTMODIFIEDDATE  ,
            a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_SAMPLETRANS_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.CREATEDBYID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
          --where instr( lower(a.COMMENTS_VOD__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMMENTS_VOD__C is not null;
       where (instr( lower(' ' || translate(trim(replace(a.COMMENTS_VOD__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1) > 0) and b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name7||' - '||SQL%ROWCOUNT||' records loaded' );
          commit;   
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END;
    ** 8.Load table MM_ADVERSE_EVENT_ALL                                                                  *
       BEGIN  
        insert into MM_ADVERSE_EVENT_ALL
        ( COUNTRY_CODE_BI__C ,
          CALLDATE         ,
          COMMENTS     ,
       COMMENTS_HTML     ,
          OWNERID       ,
       LASTMODIFIEDDATE ,
       RECORDTYPE ,
       SORT ,
          SYSTEMMODSTAMP )
      select nvl(a.country_code_bi__c, b.country_code_bi__c) as country_code_bi__c,
      a.calldate,
      a.comments,
      a.comments_html,
      a.ownerid,
      a.lastmodifieddate,
      a.recordtype,
      a.sort,
      a.systemmodstamp
      from (select
      country_code_bi__c,
      call_date_vod__c as calldate,
      next_call_notes_vod__c as comments,
      next_call_notes_vod__c_html as comments_html,
      ownerid,
      lastmodifieddate,
      'Call' as recordtype,
      '1' as sort,
      systemmodstamp
      from mf_call_ae_vd
      union
      select
      country_code_bi__c,
      lastmodifieddate as calldate,
      comments_bi__c as comments, 
      comments_bi__c_html as comments_html, 
      ownerid,
      lastmodifieddate,
      'Change Request' as recordtype,
      '2' as sort,
      systemmodstamp
      from mm_change_request_ae_vd
      union
      select
      null,
      lastmodifieddate as calldate,
      competitor_insights_bi__c as comments,
      competitor_insights_bi__c_html as comments_html,
      ownerid,
      lastmodifieddate,
      'Competitor Insight' as recordtype,
      '3' as sort,
      systemmodstamp
      from mm_competitor_insight_ae_vd
      union
      select
      null,
      lastmodifieddate as calldate,
      comment_formulary_bi__c as comments,
      comment_formulary_bi__c_html as comments_html,
      ownerid,
      lastmodifieddate,
      'Formulary' as recordtype,
      '4' as sort,
      systemmodstamp
      from mm_formulary_ae_vd
      union
      select
      null,
      lastmodifieddate as calldate,
      inquiry_text__c as comments,
      inquiry_text__c_html as comments_html,
      createdbyid as ownerid,
      lastmodifieddate,
      'Customer Request' as recordtype,
      '5' as sort,
      systemmodstamp
      from mm_med_inquiry_ae_vd
      union
      select
      null,
      lastmodifieddate as calldate,
      comments_vod__c as comments,
      comments_vod__c_html as comments_html,
      createdbyid as ownerid,
      lastmodifieddate,
      'Sample Transaction' as recordtype,
      '6' as sort,
      systemmodstamp
      from mm_sampletrans_ae_vd
      ) a LEFT OUTER JOIN mm_user_ae_vd b on a.ownerid=b.ID;
        DBMS_OUTPUT.PUT_LINE (v_table_name8||' - '||SQL%ROWCOUNT||' records loaded' ); 
        commit;
       EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
       END; 
    ** 9.Load table MM_USER_COUNTRY_AE_VD                                                               *
       BEGIN  
        insert into MM_USER_COUNTRY_AE_VD
        ( REGION       ,
          COUNTRY_CODE ,
          COUNTRY_NAME )
      select distinct
      case
      when u.country_code_bi__c in  ('AE','BH','EG','JO','KW','LB','OM','QA','SA') then ('EMEA')
      when u.country_code_bi__c in  ('AU','CN','HK','ID','IN','JP','KR','MY','PH','SG','TH','TW', 'VN') then ('APAC')
      when u.country_code_bi__c in  ('BR','CA','MX','US' ) then ('AMERICA')
          --when u.country_code_bi__c in  ('AU', 'CN','IN','JP','KR','MY', 'TH','TW') then ('APAC')
          --when u.country_code_bi__c in  ('CA','CE','CR','DO','GT','HN','NI','PA','SV','US') then ('AMERICA')
      else (null)
      end as REGION,
      u.country_code_bi__c AS COUNTRY_CODE,
      decode (u.country_code_bi__c,
      'AE', 'United Arab Emirates',
        'BH', 'Bahrain',
      'EG', 'Egypt',
      'JO', 'Jordan',
      'KW', 'Kuwait',
      'LB', 'Lebanon',
      'OM', 'Oman',
      'QA', 'Qatar',
      'SA', 'Saudi Arabia',
        'AU', 'Australia',
      'CN', 'China',
      'HK', 'Hong Kong',
      'ID', 'Indonesia',
      'IN', 'India',
        'JP', 'Japan',
      'KR', 'Korea',
      'MY', 'Malaysia',
      'PH', 'Philippines',
      'SG', 'Singapore',
      'TH', 'Thailand',
      'TW', 'Taiwan',
      'VN', 'Vietnam',
      'BR', 'Brazil',
      'CA', 'Canada',
        'MX', 'Mexico',
        'US', 'United States') AS COUNTRY_NAME
      from DA_RDW_AP.DM_USER_AE_VD u, DA_RDW_AP.DF_CALL_AE_VD c
      where u.id = c.ownerid
      and u.country_code_bi__c is not null
      order by region, country_name;
        DBMS_OUTPUT.PUT_LINE (v_table_name9||' - '||SQL%ROWCOUNT||' records loaded' ); 
        commit;
       EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
       END;
    ** 10. Load table CFG_AE_CONCAT_KEYWORD - Load concatenated data in a single record by country code *
       BEGIN  
        insert into DM_RDW_AP_VD.CFG_AE_CONCAT_KEYWORD
         (COUNTRY_CODE ,
        KEYWORD)
        select country_code, replace(output, ',', ', ') as keyword
        from
          (select country_code, wm_concat(trim(keyword)) over (partition by country_code order by rownumber) as output,
             count(keyword) over (partition by country_code order by rownumber) as running_count,
             count(keyword) over (partition by country_code) as tot_count
          from DM_RDW_AP_VD.CFG_ADVERSE_KEYWORD)
          where running_count = tot_count;
        DBMS_OUTPUT.PUT_LINE (v_table_name10||' - '||SQL%ROWCOUNT||' records loaded' ); 
        commit;
       EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
       END;  
    ** Mandatory record for burst query                                                            *
      BEGIN  
           insert into DM_RDW_AP_VD.MF_CALL_AE_VD
            ( ID                      ,
              NAME                    ,
              CALL_DATE_VOD__C        ,
              PRE_CALL_NOTES_VOD__C   ,
              NEXT_CALL_NOTES_VOD__C  ,
              NEXT_CALL_NOTES_VOD__C_HTML,
              COUNTRY_CODE_BI__C      ,
              OWNERID                 ,
              LASTMODIFIEDDATE        ,
              SYSTEMMODSTAMP)
      select
              ID                      ,
              NAME                    ,
              sysdate - 1             ,
              PRE_CALL_NOTES_VOD__C   ,
              NEXT_CALL_NOTES_VOD__C  ,
              NEXT_CALL_NOTES_VOD__C_HTML,
              COUNTRY_CODE_BI__C      ,
              OWNERID                 ,
              sysdate - 1             ,
              sysdate - 1
        from DM_RDW_AP_VD.MF_CALL_AE_VD_DUMMY;
          DBMS_OUTPUT.PUT_LINE (v_table_name2||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
         EXCEPTION
            WHEN OTHERS THEN
              v_error_count := v_error_count + 1;
              v_error_code  := TO_CHAR(sqlcode);
              v_error_text  := SUBSTR(sqlerrm, 1, 110);
              RAISE procedure_err;
      END;
    END LOAD_DM_AE_DATA_PRC;

    In following replace.. replace.. substr what are you trying to achieve? Can you please eg. so that we can try to use regular expression to do what being done by so many replace, substrs... This will help improve code performance and readability!
    ** 2. SCAN/Load table MF_CALL_AE_VD *
              replace(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10), ' '),
                      substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10), ' '),
                             instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C),
                                                   chr(10),
                                           chr(13),
                                   lower(trim(b.Keyword)),
                                   1,
                                   1),
                             length(trim(b.Keyword))),
                      '<FONT style="BACKGROUND-COLOR: yellow"><b>' ||
                      substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10), ' '),
                             instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C),
                                                   chr(10),
                                           chr(13),
                                   lower(trim(b.Keyword)),
                                   1,
                                   1),
                             length(trim(b.Keyword))) || '</b></FONT>'
                      ) as NEXT_CALL_NOTES_VOD__C_HTML,

  • Query for performance tunning

    Hi,
    Millions of records are there in this order table and it takes hours to run the below query
    update orders
    set s_last_name = decode(s_last_name, null, null, (select last_name from cust where cust_id = orders.cust_id)),
    credit_card = null;
    Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    UPDATE STATEMENT | | 35M| 1388M| 319K (3)| 01:03:55 |
    UPDATE | ORDERS | | | | |
    PARTITION RANGE ALL | | 35M| 1388M| 319K (3)| 01:03:55 |
    TABLE ACCESS FULL | ORDERS | 35M| 1388M| 319K (3)| 01:03:55 |
    TABLE ACCESS BY GLOBAL INDEX ROWID | CUST | 1 | 14 | 3 (0) | 00:00:01 |
    INDEX RANGE SCAN | CUST_PK| 1 | | 2 (0) | 00:00:01 |
    is it possible to write in a different way to improve the performance.. thanks. Bcj

    You're running an update with an uncorrelated subquery. These can be horrifically slow. You generally have 2 options:
    1. Correlated subquery
    2. Do the update inside a loop. #1 if possible will probably be faster
    1. Correlated subquery looks something like
    update table A
        setl (column1, column2) = (select column1, column2
                                                  from table2
                                                where table2.key = A.key
                                         )which might be faster, if the lookup table is properly indexed on the correlated column
    2. Update in loop looks something like
      for record in (key, select column1, column2 from table)loop
        update table2
            set column1 = record.column1, column2 = record.column2
          where table2.key = record.key
      end loop;which may be faster than the original update (or may not). This method has the advantage of allowing periodic commits; people who say you should never do periodic commits have never blown out rollback segments. If you must use the loop method commit at least 4k rows (more rows per commit is better).

Maybe you are looking for

  • How can I create a "master" document with multiple variations?

    I designed a map that will be posted at a few dozen junctions with a "you are here" symbol.  Every one will be identical with the exception of this symbol.  I don't know if there is any way to do this while preserving a "master" map that can be edite

  • File to ABAP Server Proxy Scenario

    Hi 2 all, I am running File to Server(ABAP) Proxy scenario... I have checked the ABAP Server Proxy at application server only and it is working fine....But when i am running the whole scenario my server proxy is not getting executed..( i.e my file is

  • Please help - Toplink on Websphere5.1

    Hi, I am newbie on Toplink and I am trying to use toplink to run on a sample table with EJB 2.0 CMP and Session Facade. I created a project.xml and toplink-ejb-jar.xml(renamed the session.xml for Websphere) using toplink workbench and placed in the M

  • Error code 80188308

    hi guys... I am getting the above error code while updating my Lumia 920. need help to overcome this problem... do refer to the attachment for the screen shot... many thanks in advance Attachments: wp_ss_20140902_0001.png ‏71 KB

  • How to display two "columns" in combobox?

    Hi, I need to display two strings for each row of a combobox. Say string array str1 = {"abc", "aw", "axz12"}, str2 = {"12.1", "33.123", "5.06612"}. Now I want to display them in a combo box as a "table with 2 columns", i.e. when the drop down menu is