Help in tuning the Query

Pls see this attached query. This is hitting a table which has around 110 mil recs. And this takes around 60 min to execute. IS there any way to tune it better? I am assuming that because this uses the ' With tmp as' clauses, it might be using the Indexes.
Can anyone suggest some tuning tips?
Satish
WITH all_edbc_pending_edg
     AS (SELECT
                a.day_sk,
                a.case_num,
                a.edg_num,
                a.edg_trace_id,
                a.application_dt, 
                a.current_elig_ind,
                a.payment_begin_dt payment_beg_dt
         FROM   fct_eligibility_2 a,
                dim_edg_activity_type b
         WHERE  a.current_elig_ind IN ('P','S','A')
and mod(case_num,2)=0
                AND b.eff_end_dt IS NULL
                AND b.activity_type_cd IN ('IN','RE','IR','PR','OG')
                AND a.activity_type_sk=b.activity_type_sk
, Pick_Latest_Prior_Med as
SELECT  t3.case_num,
        t3.edg_num,
        t3.current_elig_ind,
        t3.application_dt,
        t3.day_sk,
        t3.payment_beg_dt,
        t3.edg_trace_id
FROM   (SELECT t2.*,
               Row_number()
                 OVER(PARTITION BY t2.case_num,t2.edg_num, t2.application_dt ORDER BY t2.day_sk DESC, t2.payment_beg_dt DESC, t2.edg_trace_id DESC) AS rn
        FROM   all_edbc_pending_edg t2) t3
WHERE  t3.rn = 1
Select
       case_num,
       edg_num,
       application_dt,
       payment_beg_dt,
       edg_trace_id,
       current_elig_ind
FROM
        SELECT  t1.case_num,
               t1.edg_num, 
               t1.application_dt, 
               t1.payment_beg_dt,
               t1.edg_trace_id,
               t1.current_elig_ind
        FROM   (SELECT  t.*,
                       Row_number()
                         OVER(PARTITION BY t.case_num,t.edg_num ORDER BY t.day_sk DESC, t.payment_beg_dt DESC, t.edg_trace_id DESC) AS rn
                FROM   Pick_Latest_Prior_Med  t) t1
        WHERE  t1.rn = 1
        ) p
WHERE
       current_elig_ind IN ('P','S')

Check this link and post what is required as mentioned in the link.
SQL and PL/SQL FAQ
>
I am assuming that because this uses the ' With tmp as' clauses, it might be using the Indexes.
>
You don't need to assume. You can find out what's exactly happening if you follow the steps described in the above mentioned link.
Regards
Raj

Similar Messages

  • Need help in tunnig the query

    Experts,
    Plz help in tuning this query
    SELECT
    DECODE(WSH_DELIVERY_DETAILS.LOT_NUMBER,'5I27164/1U',1, TO_NUMBER(SUBSTR(WSH_DELIVERY_DETAILS.LOT_NUMBER, (LENGTH(WSH_DELIVERY_DETAILS.LOT_NUMBER) - INSTR(REVERSE(WSH_DELIVERY_DETAILS.LOT_NUMBER),'/') + 2), (INSTR(REVERSE(WSH_DELIVERY_DETAILS.LOT_NUMBER),'/')-1))) ) AS NO_OF_PLATES,
         P_FORM.DESCRIPTION FORMOFPRODUCT,
    HZ_PARTIES.PARTY_NAME CUSTOMER, HZ_CUST_ACCOUNTS.ACCOUNT_NUMBER ACCT_NUM,
         NVL(OE_ORDER_HEADERS_ALL.CUST_PO_NUMBER,'XXXX') CUST_PO,
         INITCAP(HZ_PARTIES.ADDRESS1) BILL_ADD1,
    INITCAP(HZ_PARTIES.ADDRESS2) BILL_ADD2,
    INITCAP(HZ_PARTIES.ADDRESS3) BILL_ADD3,
    INITCAP(HZ_PARTIES.ADDRESS4) BILL_ADD4,
         INITCAP(HZ_PARTIES.CITY) BILL_CITY,
    INITCAP(HZ_PARTIES.STATE) BILL_STATE,
    HZ_PARTIES.POSTAL_CODE BILL_PC,
         INITCAP(HZ_LOCATIONS.ADDRESS1) SHIP_ADD1,
    INITCAP(HZ_LOCATIONS.ADDRESS2) SHIP_ADD2,
    INITCAP(HZ_LOCATIONS.ADDRESS3) SHIP_ADD3,
    INITCAP(HZ_LOCATIONS.ADDRESS4) SHIP_ADD4,
         INITCAP(HZ_LOCATIONS.CITY) SHIP_CITY,
    INITCAP(HZ_LOCATIONS.STATE) SHIP_STATE,
    HZ_LOCATIONS.POSTAL_CODE SHIP_PC,
         OE_TRANSACTION_TYPES_TL.NAME CATEGORY ,
         OE_ORDER_HEADERS_ALL.ORDER_NUMBER,
    OE_ORDER_HEADERS_ALL.SOURCE_DOCUMENT_ID,
    OE_ORDER_HEADERS_ALL.HEADER_ID,
    OE_ORDER_HEADERS_ALL.FREIGHT_TERMS_CODE,
    /* to_char(oe_order_headers_all.ORDERED_DATE,'DD-MON-RR HH24:MI:SS') ORDER_DATE,*/
    to_char(sysdate,'DD/MM/RRRR HH24:MI:SS') ORDERED_DATE,
         ROWNUM,
    OE_ORDER_LINES_ALL.INVENTORY_ITEM_ID,
         OE_ORDER_LINES_ALL.ORDERED_ITEM,
         OE_ORDER_LINES_ALL.ORDERED_QUANTITY,
         WSH_DELIVERY_DETAILS.SHIPPED_QUANTITY+DECODE(WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID,129881,.22,0) AS SHIPPED_QUANTITY1, (WSH_DELIVERY_DETAILS.SHIPPED_QUANTITY+DECODE(WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID,129881,.22,0))*OE_ORDER_LINES_ALL.UNIT_SELLING_PRICE AS LINE_PRICE,
         OE_ORDER_LINES_ALL.UNIT_SELLING_PRICE,
         JA_IN_RG_I.FOR_HOME_USE_PAY_ED_VAL,
    ----      SUBSTR(JA_IN_RG_I.EXCISE_INVOICE_NUMBER,1,2)|| SUBSTR(JA_IN_RG_I.EXCISE_INVOICE_NUMBER,4,8) INVOICE_NO,
         JA_IN_RG_I.EXCISE_INVOICE_NUMBER INVOICE_NO,
    to_char(JA_IN_RG_I.CREATION_DATE,'DD/MM/RRRR') INVOICE_DATE1,
         to_char(JA_IN_RG_I.EXCISE_INVOICE_DATE,'DD-MON-RR HH24:MI:SS') INV_DATE,
         to_char(JA_IN_RG_I.CREATION_DATE,'DD/MM/RRRR HH24:MI:SS') INVOICE_DATE,
         JA_IN_RG_I.EXCISE_DUTY_RATE,
         JA_IN_RG_I.EXCISE_DUTY_AMOUNT,
         WSH_DELIVERY_DETAILS.LOT_NUMBER,
    WSH_TRIPS.CARRIER_ID CARRIER_ID,
    WSH_TRIPS.VEHICLE_NUM_PREFIX,
    WSH_TRIPS.SEAL_CODE,
    WSH_TRIPS.ROUTING_INSTRUCTIONS,
    WSH_TRIPS.OPERATOR, WSH_NEW_DELIVERIES. DELIVERY_ID,
    WSH_NEW_DELIVERIES. ADDITIONAL_SHIPMENT_INFO TRUCK_NO,
         WSH_TRIPS.MODE_OF_TRANSPORT VEHICLE_TYPE,
    WSH_TRIPS.ATTRIBUTE6||' '|| WSH_TRIPS.ATTRIBUTE7||' '|| WSH_TRIPS.ATTRIBUTE8 REMARKS,
         WSH_TRIPS.ATTRIBUTE1 LR_NO, WSH_TRIPS.ATTRIBUTE7,
         WSH_TRIPS.ATTRIBUTE2 LR_DATE,
         DECODE(WSH_TRIPS.ATTRIBUTE3, '', '', 'ARE NO '||WSH_TRIPS.ATTRIBUTE3) AS ARE_NO,
         DECODE(WSH_TRIPS.ATTRIBUTE6, '', '', WSH_TRIPS.ATTRIBUTE6) AS REMARK1,
         DECODE(WSH_TRIPS.ATTRIBUTE4, '', '', 'R.P. NO. ' ||WSH_TRIPS.ATTRIBUTE4) AS PERMIT,
         DECODE(WSH_TRIPS.ATTRIBUTE5, '', '', 'Export Under '||WSH_TRIPS.ATTRIBUTE5) AS EXPORT_UNDER,
         DECODE(WSH_NEW_DELIVERIES.PORT_OF_DISCHARGE,'','', 'Seal No : '||WSH_NEW_DELIVERIES.PORT_OF_DISCHARGE) AS SEAL_NO,
         DECODE(WSH_NEW_DELIVERIES.DESCRIPTION, '', '', 'Container No : ' ||WSH_NEW_DELIVERIES.DESCRIPTION) AS CONTAINER_NO,
         MTL_SYSTEM_ITEMS_B.ATTRIBUTE4 AS EXCISE_TARIFF_NO,
         --MTL_SYSTEM_ITEMS_B.DESCRIPTION,
         HZ_CUST_ACCOUNTS.ACCOUNT_NUMBER,
         JSW_LOT_PACKSLIP.PACKSLIP_NO PACKSLIP,
         PR_TYPE.DESCRIPTION ||' ,'||
         P_FORM.DESCRIPTION || ' ,'||
         PR_GRADE.DESCRIPTION ||' ,'||
         PR_QTY.DESCRIPTION || ' ,'||
         DECODE(SUBSTR(PR_STL.DESCRIPTION,1,3),'Not','', PR_STL.DESCRIPTION) DESCRIPTION ,
    HZ_CUST_ACCT_SITES_ALL.ATTRIBUTE7 S_CST_NO,
    HZ_CUST_ACCT_SITES_ALL.ATTRIBUTE6 S_LST_NO,
    HZ_CUST_ACCT_SITES_ALL.ATTRIBUTE5 S_ECC_NO,
    A.ATTRIBUTE7 B_CST_NO,
    A.ATTRIBUTE6 B_LST_NO,
    INTERFACECRM.JSW_MES_COMMON_TNGL_T.JSW_ADDMINUTES(WSH_TRIPS.VEHICLE_NUM_PREFIX) POSTFIX_NUM
    FROM -- jsw_vat_slno,
         MTL_PARAMETERS,
         HZ_PARTIES,
         HZ_CUST_ACCOUNTS,
         HZ_LOCATIONS,
         HZ_PARTY_SITES,
         HZ_CUST_ACCT_SITES_ALL,
         HZ_CUST_SITE_USES_ALL,
    HZ_CUST_ACCT_SITES_ALL A,
    HZ_CUST_SITE_USES_ALL B,
         OE_TRANSACTION_TYPES_TL,
         JA_IN_RG_I,
         WSH_DELIVERY_DETAILS,
         OE_ORDER_LINES_ALL,
         OE_ORDER_HEADERS_ALL,
         WSH_DELIVERY_ASSIGNMENTS,
         WSH_NEW_DELIVERIES,
         WSH_DELIVERY_LEGS,
         WSH_TRIP_STOPS,
         WSH_TRIPS,
         MTL_SYSTEM_ITEMS_B,
         JSW_LOT_PACKSLIP,
         IC_TRAN_PND,
                   JSW_ITM_SEARCH_PRD_TYP          PR_TYPE,
              JSW_ITM_SEARCH_PRD_FRM          P_FORM     ,
                   JSW_ITM_SEARCH_PRD_GRD          PR_GRADE,      
              JSW_ITM_SEARCH_QUALITY_LEVEL PR_QTY,      
                   JSW_ITEM_SEARCH_SLITTING      PR_STL
    WHERE /* jsw_vat_slno.excise_invoice_number=ja_in_rg_i.excise_invoice_number and jsw_vat_slno.organization_id = ja_in_rg_i.organization_id */
    HZ_PARTIES.PARTY_ID = HZ_CUST_ACCOUNTS.PARTY_ID
         AND HZ_CUST_ACCOUNTS.CUST_ACCOUNT_ID = OE_ORDER_HEADERS_ALL.SOLD_TO_ORG_ID
         AND OE_ORDER_HEADERS_ALL.SHIP_TO_ORG_ID = HZ_CUST_SITE_USES_ALL.SITE_USE_ID
         AND HZ_CUST_SITE_USES_ALL.CUST_ACCT_SITE_ID = HZ_CUST_ACCT_SITES_ALL.CUST_ACCT_SITE_ID
    AND OE_ORDER_HEADERS_ALL.INVOICE_TO_ORG_ID = B.SITE_USE_ID
         AND B.CUST_ACCT_SITE_ID                          = A.CUST_ACCT_SITE_ID
         AND HZ_CUST_ACCT_SITES_ALL.PARTY_SITE_ID      = HZ_PARTY_SITES.PARTY_SITE_ID
         AND HZ_PARTY_SITES.LOCATION_ID = HZ_LOCATIONS.LOCATION_ID
         AND OE_ORDER_LINES_ALL.SHIP_FROM_ORG_ID = MTL_PARAMETERS.ORGANIZATION_ID
         AND OE_ORDER_HEADERS_ALL.ORDER_TYPE_ID = OE_TRANSACTION_TYPES_TL.TRANSACTION_TYPE_ID
    and upper(oe_transaction_types_tl.description) not like '%SUP%'
         AND OE_ORDER_HEADERS_ALL.HEADER_ID = WSH_DELIVERY_DETAILS.SOURCE_HEADER_ID
         AND OE_ORDER_HEADERS_ALL.HEADER_ID = OE_ORDER_LINES_ALL.HEADER_ID
         AND OE_ORDER_LINES_ALL.LINE_ID = WSH_DELIVERY_DETAILS.SOURCE_LINE_ID
         AND TO_CHAR(WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID ) = JA_IN_RG_I.REF_DOC_ID
         AND WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID = WSH_DELIVERY_ASSIGNMENTS.DELIVERY_DETAIL_ID
         AND WSH_DELIVERY_ASSIGNMENTS.DELIVERY_ID = WSH_NEW_DELIVERIES.DELIVERY_ID
         AND WSH_NEW_DELIVERIES.DELIVERY_ID = WSH_DELIVERY_LEGS.DELIVERY_ID
         AND WSH_DELIVERY_LEGS.PICK_UP_STOP_ID = WSH_TRIP_STOPS.STOP_ID
         AND WSH_TRIP_STOPS.TRIP_ID                = WSH_TRIPS.TRIP_ID
    /* Input parameter can be either Invoice number or Delivery Id */
         AND (WSH_NEW_DELIVERIES.DELIVERY_ID = :DEL_ID OR JA_IN_RG_I.EXCISE_INVOICE_NUMBER = :INVOICE_NUMBER)
         AND NVL(WSH_DELIVERY_DETAILS.SHIPPED_QUANTITY,0) <>0
         AND     MTL_SYSTEM_ITEMS_B.ORGANIZATION_ID     = WSH_DELIVERY_DETAILS.ORGANIZATION_ID
         AND     MTL_SYSTEM_ITEMS_B.INVENTORY_ITEM_ID = WSH_DELIVERY_DETAILS.INVENTORY_ITEM_ID
         AND IC_TRAN_PND.LINE_DETAIL_ID               = WSH_DELIVERY_DETAILS.DELIVERY_DETAIL_ID
         AND     JSW_LOT_PACKSLIP.LOT_ID                    = IC_TRAN_PND.LOT_ID(+)
         AND     JSW_LOT_PACKSLIP.DELIVERY_ID          = WSH_NEW_DELIVERIES.DELIVERY_ID(+)
         AND      IC_TRAN_PND.LINE_ID                    = OE_ORDER_LINES_ALL.LINE_ID                                                  
         AND     IC_TRAN_PND.DELETE_MARK                = 0
         AND IC_TRAN_PND.COMPLETED_IND      = 1
         AND      IC_TRAN_PND.STAGED_IND                    =     1
         AND     P_FORM.CODE(+)                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,3,2)
         AND     PR_TYPE.CODE                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,1,2)
         AND     PR_TYPE.CODE                                   = P_FORM.PRD_TYPE_CODE
         AND     P_FORM.CODE                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,3,2)
    AND     P_FORM.CODE                                   = PR_GRADE.PRD_FRM_CODE
         AND     PR_GRADE.CODE                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,5,2)     
         AND     PR_GRADE.CODE                                   = PR_QTY.PRD_GRD_CODE
         AND     PR_QTY.CODE                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,7,2)
         AND     PR_STL.PROD_CODE                              = PR_TYPE.CODE
         AND     PR_STL.QUALITY_LEVEL_CODE                    = PR_QTY.CODE
         AND     PR_STL.CODE                                   = substr(OE_ORDER_LINES_ALL.ORDERED_ITEM,9,2)
         AND rownum=1
    thanks,
    baskar.l

    Here is the explain plan
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 1 | 920 | 12628 |
    | 1 | COUNT STOPKEY | | | | |
    | 2 | NESTED LOOPS | | 1 | 920 | 12628 |
    | 3 | NESTED LOOPS | | 1 | 728 | 12627 |
    | 4 | NESTED LOOPS | | 1 | 718 | 12626 |
    | 5 | NESTED LOOPS | | 1 | 684 | 12625 |
    | 6 | NESTED LOOPS | | 1 | 674 | 12624 |
    | 7 | NESTED LOOPS | | 1 | 665 | 12623 |
    | 8 | NESTED LOOPS | | 1 | 655 | 12622 |
    | 9 | NESTED LOOPS | | 1 | 532 | 12621 |
    | 10 | NESTED LOOPS | | 1 | 522 | 12620 |
    | 11 | FILTER | | | | |
    | 12 | NESTED LOOPS OUTER | | | | |
    | 13 | NESTED LOOPS | | 1 | 494 | 12617 |
    | 14 | NESTED LOOPS | | 1 | 477 | 12614 |
    | 15 | NESTED LOOPS | | 1 | 467 | 12611 |
    | 16 | NESTED LOOPS | | 1 | 382 | 12610 |
    | 17 | NESTED LOOPS | | 1 | 366 | 12609 |
    | 18 | NESTED LOOPS | | 1 | 321 | 12606 |
    | 19 | FILTER | | | | |
    | 20 | HASH JOIN OUTER | | | | |
    | 21 | TABLE ACCESS BY INDEX ROWID| IC_TRAN_PND | 1 | 22 | 3 |
    | 22 | NESTED LOOPS | | 1 | 292 | 12601 |
    | 23 | HASH JOIN | | 1 | 270 | 12598 |
    | 24 | NESTED LOOPS | | 4011 | 908K| 6272 |
    | 25 | HASH JOIN | | 4012 | 893K| 6272 |
    | 26 | TABLE ACCESS FULL | JSW_ITM_SEARCH_PRD_GRD | 33 | 759 | 2 |
    | 27 | HASH JOIN | | 20547 | 4113K| 6269 |
    | 28 | TABLE ACCESS FULL | JSW_ITM_SEARCH_QUALITY_LEVEL | 54 | 1296 | 2 |
    | 29 | HASH JOIN | | 24352 | 4304K| 6266 |
    | 30 | TABLE ACCESS FULL | JSW_ITM_SEARCH_PRD_TYP | 7 | 154 | 2 |
    | 31 | HASH JOIN | | 170K| 25M| 6260 |
    | 32 | TABLE ACCESS FULL | JSW_ITEM_SEARCH_SLITTING | 73 | 1971 | 2 |
    | 33 | HASH JOIN | | 44367 | 5719K| 6257 |
    | 34 | HASH JOIN | | 4469 | 410K| 367 |
    | 35 | TABLE ACCESS FULL| OE_TRANSACTION_TYPES_TL | 18 | 846 | 4 |
    | 36 | TABLE ACCESS FULL| OE_ORDER_HEADERS_ALL | 38240 | 1755K| 362 |
    | 37 | TABLE ACCESS FULL | OE_ORDER_LINES_ALL | 379K| 13M| 5761 |
    | 38 | INDEX UNIQUE SCAN | MTL_PARAMETERS_U1 | 1 | 4 | |
    | 39 | TABLE ACCESS FULL | WSH_DELIVERY_DETAILS | 579K| 21M| 5926 |
    | 40 | INDEX RANGE SCAN | IC_TRAN_PND_N1 | 2 | | 2 |
    | 41 | TABLE ACCESS FULL | JSW_ITM_SEARCH_PRD_FRM | 16 | 272 | 2 |
    | 42 | TABLE ACCESS BY INDEX ROWID | MTL_SYSTEM_ITEMS_B | 1 | 12 | 2 |
    | 43 | INDEX UNIQUE SCAN | MTL_SYSTEM_ITEMS_B_U1 | 1 | | 1 |
    | 44 | TABLE ACCESS BY INDEX ROWID | JA_IN_RG_I | 1 | 45 | 3 |
    | 45 | INDEX RANGE SCAN | JA_IN_RG_I_N3 | 1 | | 2 |
    | 46 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCOUNTS | 1 | 16 | 1 |
    | 47 | INDEX UNIQUE SCAN | HZ_CUST_ACCOUNTS_U1 | 1 | | |
    | 48 | TABLE ACCESS BY INDEX ROWID | HZ_PARTIES | 1 | 85 | 1 |
    | 49 | INDEX UNIQUE SCAN | HZ_PARTIES_U1 | 1 | | |
    | 50 | TABLE ACCESS BY INDEX ROWID | WSH_DELIVERY_ASSIGNMENTS | 1 | 10 | 3 |
    | 51 | INDEX RANGE SCAN | WSH_DELIVERY_ASSIGNMENTS_N3 | 1 | | 2 |
    | 52 | TABLE ACCESS BY INDEX ROWID | JSW_LOT_PACKSLIP | 1 | 17 | 3 |
    | 53 | INDEX RANGE SCAN | JSW_LOT_PACKSLIP_N1 | 1 | | 2 |
    | 54 | TABLE ACCESS BY INDEX ROWID | WSH_NEW_DELIVERIES | 1 | 18 | 1 |
    | 55 | INDEX UNIQUE SCAN | WSH_NEW_DELIVERIES_U1 | 1 | | |
    | 56 | TABLE ACCESS BY INDEX ROWID | WSH_DELIVERY_LEGS | 1 | 10 | 2 |
    | 57 | INDEX RANGE SCAN | WSH_DELIVERY_LEGS_N1 | 1 | | 1 |
    | 58 | TABLE ACCESS BY INDEX ROWID | WSH_TRIP_STOPS | 1 | 10 | 1 |
    | 59 | INDEX UNIQUE SCAN | WSH_TRIP_STOPS_U1 | 1 | | |
    | 60 | TABLE ACCESS BY INDEX ROWID | WSH_TRIPS | 1 | 123 | 1 |
    | 61 | INDEX UNIQUE SCAN | WSH_TRIPS_U1 | 1 | | |
    | 62 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_SITE_USES_ALL | 1 | 10 | 1 |
    | 63 | INDEX UNIQUE SCAN | HZ_CUST_SITE_USES_U1 | 1 | | |
    | 64 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCT_SITES_ALL | 1 | 9 | 1 |
    | 65 | INDEX UNIQUE SCAN | HZ_CUST_ACCT_SITES_U1 | 1 | | |
    | 66 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_SITE_USES_ALL | 1 | 10 | 1 |
    | 67 | INDEX UNIQUE SCAN | HZ_CUST_SITE_USES_U1 | 1 | | |
    | 68 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCT_SITES_ALL | 1 | 34 | 1 |
    | 69 | INDEX UNIQUE SCAN | HZ_CUST_ACCT_SITES_U1 | 1 | | |
    | 70 | TABLE ACCESS BY INDEX ROWID | HZ_PARTY_SITES | 1 | 10 | 1 |
    | 71 | INDEX UNIQUE SCAN | HZ_PARTY_SITES_U1 | 1 | | |
    | 72 | TABLE ACCESS BY INDEX ROWID | HZ_LOCATIONS | 1 | 192 | 1 |
    | 73 | INDEX UNIQUE SCAN | HZ_LOCATIONS_U1 | 1 | | |
    we need to tune this query to reduce it time of execution as our users are very much affected in running requests.
    thanks,
    baskar.l

  • Need help in refining the query

    Hello Experts,
    Need your help in refining the query further more.
    table structure 
    Mskey  Col A Col B
    1   empno [20141127-20151128]1234
    1   empno [20151201-99991231]232544
    1   salutation [20141127-99991231]Mrs
    1   salutation [20151127-99991231]Mr
    2   empno [20141127-20151128]1234
    2   empno [20151201-99991231]232544
    2   salutation [20141127-99991231]Mrs
    2   salutation [20151127-99991231]Mr
    My requirement is to find the list of overlapping records based on the dates
    user details may be varying from time to time as new data would be pushed through HR systems to identity store via an interface.
    The job is getting failed whenever there is any overlapping with dates. So we proactively decided to schedule a job in this regards which runs weekly and would let us know for which and all the users there is overlapping dates are there, so that we can send the list to HR team for pushing new data.
    Overlapping Issue Example:
    The users employee id for an year it is 1234 and later he moved to another department and his employee id got changed and it became 2345 remaining all details are same. So the HR systems send the data for this user as empno - [20141127-20151128]1234 and empno - [20151201-99991231]232544
    it means from 20141127 to 20151128 his employee no is 1234 and from 20151201 to 99991231 his employee would be 2345.
    This is a correct case and the tool would accept this data.
    the below cases are invald
    Case 1: 1 salutation [20141127-99991231]Mrs 1 salutation [20151127-99991231]Mr
    Case 2: 2 salutation [20141127-99991231]Mrs 2 salutation [20141127-99991231]Mr
    So we wanted to find these overlapping records from tables.
    My Query:
    I am able to successfully write query for the case 2 type but unable to write for case1.
    select id,colA
    count(left(ColB,CHARINDEX(']',ColB))) as 'Count'
    from tblA with (nolock)
    where id in (Select distinct id from tblb with (nolock))
    group by id, cola,left(ColB,CHARINDEX(']',ColB))
    having count(left(ColB,CHARINDEX(']',ColB)))>1

    Finally got the required answer with the below query
    WITH Cte AS
    SELECT ID,ColA,ColB,ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS RN,
    CAST(SUBSTRING(ColB,2,CHARINDEX('-',ColB)-2) AS DATE) AS StartDT,
    CAST(SUBSTRING(ColB,CHARINDEX('-',ColB)+1,8) AS DATE)  AS EndDT  FROM TblA
    SELECT c1.ID, c1.ColA,c1.ColB
    FROM Cte c1 JOIN Cte c2
    ON c1.RN != c2.RN
    AND c1.ID=c2.ID
    AND c1.ColA=c2.ColA
    AND (c1.StartDT BETWEEN c2.StartDT AND c2.EndDT OR c2.StartDT BETWEEN c1.StartDT AND c1.EndDT )

  • Request for help in tuning the server which is running opmn process.

    Hi Folks,
    I request for an help in tuning the server which is running oracle app server opmn process , It is chewing arround 40% of the CPU resource,and our sysadmin is back of me to resolve this issues.
    any feedback on this is highly appriciated...
    Thanks in advance

    Re: How to Achieve Performance Tuning
    I hope you may find answers here..
    Sharma

  • Help to rewrite the query --performance issue

    Hi ,
    Please help to rewrite the query since it's performance is not good.Especially second inline query(CASE statements are therein select caluse ..)is taking more cost.
    Database Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi
    SELECT *
    FROM
      (SELECT q.*,
        COUNT(*) OVER() AS record_count,
        ROWNUM          AS row_num
      FROM
        (SELECT ExName.examiner_code,
          examiner_name,
          :v_year,
          :v_month,
          count_fb,
          NVL(count_entered_fb, 0) count_entered_fb,
          NVL(count_sent_fb, 0) count_sent_fb,
          NVL(count_edited_fb, 0) count_edited_fb,
          NVL(count_complete_fb, 0) count_complete_fb,
          NVL(count_withibcardiff_fb, 0) count_withibcardiff_fb
        FROM
          (SELECT examiner_code,
            COUNT(*) AS count_fb
          FROM
            (SELECT
                        examiner_code,
              paper_code,
              assessment_school
            FROM
              ( SELECT DISTINCT ce.examiner_code,
                ce.paper_code,
                ce.assessment_school
              FROM
                (SELECT
                  DISTINCT assessment_school,
                  paper_code,
                  examiner_code
                FROM candidate_examiner_allocation cea
                WHERE cea.element = 'Moderation of IA'
                AND cea.year      = :v_year
                AND cea.month     = :v_month
                ) ce,
                subject_group sg,
                subject_component sc
              WHERE (:v_padded_examiner_code IS NULL
              OR ce.examiner_code            = :v_padded_examiner_code)
              AND (:v_subject_group          IS NULL
              OR sg.group_number             = :v_subject_group)
              AND sg.year                    = :v_year
              AND sg.month                   = :v_month
              AND sc.year                    = :v_year
              AND sc.month                   = :v_month
              AND sc.paper_code              = ce.paper_code
              AND sc.subject                 = sg.subject
              AND sc.lvl                     = sg.lvl
              AND (:v_subject                IS NULL
              OR sc.subject                  = :v_subject)
              AND (:v_lvl                    IS NULL
              OR sc.lvl                      = :v_lvl)
              ) ea
          GROUP BY examiner_code
          ) ExName,
          (SELECT examiner_code,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'ENTERED'
              THEN 1
              ELSE NULL
            END) AS count_entered_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'SENT'
              THEN 1
              ELSE NULL
            END) AS count_sent_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'EDITED'
              THEN 1
              ELSE NULL
            END) AS count_edited_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'COMPLETE'
              THEN 1
              ELSE NULL
            END) AS count_complete_fb,
            COUNT(
            CASE
              WHEN UPPER(wfi.status) = 'WITH IBCARDIFF'
              THEN 1
              ELSE NULL
            END) AS count_withibcardiff_fb
          FROM ia_instances ia1,
            workflow_instance wfi
          WHERE wfi.instance_id = ia1.workflow_instance_id
          AND ia1.year          = :v_year
          AND ia1.month         = :v_month
          GROUP BY ia1.year,
            ia1.month,
            examiner_code
          ) iaF,
          (SELECT person_code,
            title
            || ' '
            || firstname
            || ' '
            || lastname AS examiner_name
          FROM person
          WHERE :v_examiner_name IS NULL
          OR UPPER(title
            || ' '
            || firstname
            || ' '
            || lastname) LIKE :v_search_examiner_name
          ) P
        WHERE ExName.examiner_code = iaF.examiner_code (+)
        AND ExName.examiner_code   = p.person_code
        ORDER BY ExName.examiner_code
        ) q
      ) rc
    WHERE row_num >= :v_start_row
    AND row_num   <= (:v_start_row+(:v_max_row-1));explain plan
    line 1: SQLPLUS Command Skipped: set linesize 130
    line 2: SQLPLUS Command Skipped: set pagesize 0
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    Plan hash value: 1581970599                                                                                                                                                                                                                                                                                 
    | Id  | Operation                                 | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                                                                                                                                                        
    |   0 | SELECT STATEMENT                          |                                |     1 |   276 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |*  1 |  FILTER                                   |                                |       |       |       |            |          |                                                                                                                                                                        
    |*  2 |   VIEW                                    |                                |     1 |   276 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   3 |    WINDOW BUFFER                          |                                |     1 |   250 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   4 |     COUNT                                 |                                |       |       |       |            |          |                                                                                                                                                                        
    |   5 |      VIEW                                 |                                |     1 |   250 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   6 |       SORT ORDER BY                       |                                |     1 |   119 |       |  2187   (6)| 00:00:34 |                                                                                                                                                                        
    |   7 |        NESTED LOOPS                       |                                |     1 |   119 |       |  2186   (6)| 00:00:34 |                                                                                                                                                                        
    |*  8 |         HASH JOIN OUTER                   |                                |     1 |    92 |       |  2185   (6)| 00:00:34 |                                                                                                                                                                        
    |   9 |          VIEW                             |                                |     1 |    20 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  10 |           SORT GROUP BY                   |                                |     1 |     7 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  11 |            VIEW                           |                                |     1 |     7 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  12 |             SORT UNIQUE                   |                                |     1 |   127 |       |    51   (4)| 00:00:01 |                                                                                                                                                                        
    |  13 |              NESTED LOOPS                 |                                |     1 |   127 |       |    50   (2)| 00:00:01 |                                                                                                                                                                        
    |* 14 |               HASH JOIN                   |                                |     1 |    68 |       |    44   (3)| 00:00:01 |                                                                                                                                                                        
    |* 15 |                TABLE ACCESS BY INDEX ROWID| SUBJECT_COMPONENT              |    13 |   520 |       |    40   (0)| 00:00:01 |                                                                                                                                                                        
    |* 16 |                 INDEX RANGE SCAN          | SUBJECT_COMPONENT_ASSESS_TYPE  |  1059 |       |       |     9   (0)| 00:00:01 |                                                                                                                                                                        
    |* 17 |                INDEX RANGE SCAN           | SUBJECT_GROUP_PK               |    41 |  1148 |       |     3   (0)| 00:00:01 |                                                                                                                                                                        
    |* 18 |               INDEX RANGE SCAN            | CEA_AUTOMATIC_ALLOCATION_STATS |     5 |   295 |       |     6   (0)| 00:00:01 |                                                                                                                                                                        
    |  19 |          VIEW                             |                                |   679 | 48888 |       |  2133   (6)| 00:00:33 |                                                                                                                                                                        
    |  20 |           SORT GROUP BY                   |                                |   679 | 25123 |       |  2133   (6)| 00:00:33 |                                                                                                                                                                        
    |* 21 |            HASH JOIN                      |                                | 52408 |  1893K|  1744K|  2126   (6)| 00:00:33 |                                                                                                                                                                        
    |  22 |             TABLE ACCESS BY INDEX ROWID   | IA_INSTANCES                   | 52408 |  1125K|       |   688   (1)| 00:00:11 |                                                                                                                                                                        
    |* 23 |              INDEX RANGE SCAN             | IND_IA_INSTANCES               | 49077 |       |       |   137   (2)| 00:00:03 |                                                                                                                                                                        
    |  24 |             TABLE ACCESS FULL             | WORKFLOW_INSTANCE              |  1075K|    15M|       |   960   (7)| 00:00:15 |                                                                                                                                                                        
    |* 25 |         TABLE ACCESS BY INDEX ROWID       | PERSON                         |     1 |    27 |       |     1   (0)| 00:00:01 |                                                                                                                                                                        
    |* 26 |          INDEX UNIQUE SCAN                | PERSON_PK                      |     1 |       |       |     0   (0)| 00:00:01 |                                                                                                                                                                        
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - filter(TO_NUMBER(:V_START_ROW)<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                                                   
       2 - filter("ROW_NUM">=TO_NUMBER(:V_START_ROW) AND "ROW_NUM"<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                          
       8 - access("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE"(+))                                                                                                                                                                                                                                            
      14 - access("SC"."SUBJECT"="SG"."SUBJECT" AND "SC"."LVL"="SG"."LVL")                                                                                                                                                                                                                                      
      15 - filter((:V_SUBJECT IS NULL OR "SC"."SUBJECT"=:V_SUBJECT) AND ("SC"."LVL"=:V_LVL OR :V_LVL IS NULL))                                                                                                                                                                                                  
      16 - access("SC"."YEAR"=TO_NUMBER(:V_YEAR) AND "SC"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
      17 - access("SG"."YEAR"=TO_NUMBER(:V_YEAR) AND "SG"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
           filter(:V_SUBJECT_GROUP IS NULL OR "SG"."GROUP_NUMBER"=TO_NUMBER(:V_SUBJECT_GROUP))                                                                                                                                                                                                                  
      18 - access("CEA"."YEAR"=TO_NUMBER(:V_YEAR) AND "CEA"."MONTH"=:V_MONTH AND "SC"."PAPER_CODE"="PAPER_CODE" AND                                                                                                                                                                                             
                  "CEA"."ELEMENT"='Moderation of IA')                                                                                                                                                                                                                                                           
           filter("CEA"."ELEMENT"='Moderation of IA' AND (:V_PADDED_EXAMINER_CODE IS NULL OR                                                                                                                                                                                                                    
                  "EXAMINER_CODE"=:V_PADDED_EXAMINER_CODE))                                                                                                                                                                                                                                                     
      21 - access("WFI"."INSTANCE_ID"="IA1"."WORKFLOW_INSTANCE_ID")                                                                                                                                                                                                                                             
      23 - access("IA1"."YEAR"=TO_NUMBER(:V_YEAR) AND "IA1"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                   
      25 - filter(:V_EXAMINER_NAME IS NULL OR UPPER("TITLE"||' '||"FIRSTNAME"||' '||"LASTNAME") LIKE :V_SEARCH_EXAMINER_NAME)                                                                                                                                                                                   
      26 - access("EXNAME"."EXAMINER_CODE"="PERSON_CODE")                                                                                                                                                                                                                                                       
    53 rows selected

    Hi,
    please find the below rigjt explan paln.
    PLAN_TABLE_OUTPUT                                                                                                                                                                                                                                                                                           
    SQL_ID  2ct41vyyzqyh7, child number 0                                                                                                                                                                                                                                                                       
    SELECT *  FROM    (SELECT q.*,      COUNT(*) OVER() AS record_count,      ROWNUM          AS row_num    FROM      (SELECT                                                                                                                                                                                   
    ExName.examiner_code,        examiner_name,        :v_year,        :v_month,        count_fb,        NVL(count_entered_fb,                                                                                                                                                                                  
    0) count_entered_fb,        NVL(count_sent_fb, 0) count_sent_fb,        NVL(count_edited_fb, 0) count_edited_fb,                                                                                                                                                                                            
    NVL(count_complete_fb, 0) count_complete_fb,        NVL(count_withibcardiff_fb, 0) count_withibcardiff_fb      FROM                                                                                                                                                                                         
    (SELECT examiner_code,          COUNT(*) AS count_fb        FROM          (SELECT                                                                                                                                                                                                 
           examiner_code,            paper_code,            assessment_school          FROM            ( SELECT DISTINCT                                                                                                                                                                                        
    ce.examiner_code,              ce.paper_code,              ce.assessment_school            FROM              (SELECT                                                                                                                                                                                        
                            DISTINCT assessment_school,                                                                                                                                                                                                          
    paper_code,                examiner                                                                                                                                                                                                                                                                         
    Plan hash value: 651311258                                                                                                                                                                                                                                                                                  
    | Id  | Operation                                | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |                                                                                                                                                                         
    |   0 | SELECT STATEMENT                         |                                |       |       |       |  2785 (100)|          |                                                                                                                                                                         
    |*  1 |  FILTER                                  |                                |       |       |       |            |          |                                                                                                                                                                         
    |*  2 |   VIEW                                   |                                |     4 |  1104 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   3 |    WINDOW BUFFER                         |                                |     4 |  1000 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   4 |     COUNT                                |                                |       |       |       |            |          |                                                                                                                                                                         
    |   5 |      VIEW                                |                                |     4 |  1000 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   6 |       NESTED LOOPS                       |                                |     4 |   476 |       |  2785   (7)| 00:00:43 |                                                                                                                                                                         
    |   7 |        MERGE JOIN OUTER                  |                                |     4 |   368 |       |  2781   (7)| 00:00:43 |                                                                                                                                                                         
    |   8 |         VIEW                             |                                |     4 |    80 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |   9 |          SORT GROUP BY                   |                                |     4 |    28 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  10 |           VIEW                           |                                |     4 |    28 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  11 |            SORT UNIQUE                   |                                |     4 |   508 |       |    72   (3)| 00:00:02 |                                                                                                                                                                         
    |  12 |             NESTED LOOPS                 |                                |     4 |   508 |       |    71   (2)| 00:00:02 |                                                                                                                                                                         
    |* 13 |              HASH JOIN                   |                                |     1 |    68 |       |    44   (3)| 00:00:01 |                                                                                                                                                                         
    |* 14 |               TABLE ACCESS BY INDEX ROWID| SUBJECT_COMPONENT              |    13 |   520 |       |    40   (0)| 00:00:01 |                                                                                                                                                                         
    |* 15 |                INDEX RANGE SCAN          | SUBJECT_COMPONENT_ASSESS_TYPE  |  1059 |       |       |     9   (0)| 00:00:01 |                                                                                                                                                                         
    |* 16 |               INDEX RANGE SCAN           | SUBJECT_GROUP_PK               |    41 |  1148 |       |     3   (0)| 00:00:01 |                                                                                                                                                                         
    |* 17 |              INDEX RANGE SCAN            | CEA_AUTOMATIC_ALLOCATION_STATS |    30 |  1770 |       |    27   (0)| 00:00:01 |                                                                                                                                                                         
    |* 18 |         SORT JOIN                        |                                |   576 | 41472 |       |  2709   (7)| 00:00:42 |                                                                                                                                                                         
    |  19 |          VIEW                            |                                |   576 | 41472 |       |  2708   (7)| 00:00:42 |                                                                                                                                                                         
    |  20 |           SORT GROUP BY                  |                                |   576 | 21312 |       |  2708   (7)| 00:00:42 |                                                                                                                                                                         
    |* 21 |            HASH JOIN                     |                                | 52408 |  1893K|  1744K|  2701   (7)| 00:00:41 |                                                                                                                                                                         
    |* 22 |             TABLE ACCESS FULL            | IA_INSTANCES                   | 52408 |  1125K|       |  1263   (6)| 00:00:20 |                                                                                                                                                                         
    |  23 |             TABLE ACCESS FULL            | WORKFLOW_INSTANCE              |  1075K|    15M|       |   960   (7)| 00:00:15 |                                                                                                                                                                         
    |* 24 |        TABLE ACCESS BY INDEX ROWID       | PERSON                         |     1 |    27 |       |     1   (0)| 00:00:01 |                                                                                                                                                                         
    |* 25 |         INDEX UNIQUE SCAN                | PERSON_PK                      |     1 |       |       |     0   (0)|          |                                                                                                                                                                         
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                         
       1 - filter(TO_NUMBER(:V_START_ROW)<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))                                                                                                                                                                                                                   
       2 - filter(("ROW_NUM">=TO_NUMBER(:V_START_ROW) AND "ROW_NUM"<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1)))                                                                                                                                                                                        
      13 - access("SC"."SUBJECT"="SG"."SUBJECT" AND "SC"."LVL"="SG"."LVL")                                                                                                                                                                                                                                      
      14 - filter(((:V_SUBJECT IS NULL OR "SC"."SUBJECT"=:V_SUBJECT) AND ("SC"."LVL"=:V_LVL OR :V_LVL IS NULL)))                                                                                                                                                                                                
      15 - access("SC"."YEAR"=TO_NUMBER(:V_YEAR) AND "SC"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
      16 - access("SG"."YEAR"=TO_NUMBER(:V_YEAR) AND "SG"."MONTH"=:V_MONTH)                                                                                                                                                                                                                                     
           filter((:V_SUBJECT_GROUP IS NULL OR "SG"."GROUP_NUMBER"=TO_NUMBER(:V_SUBJECT_GROUP)))                                                                                                                                                                                                                
      17 - access("CEA"."YEAR"=TO_NUMBER(:V_YEAR) AND "CEA"."MONTH"=:V_MONTH AND "SC"."PAPER_CODE"="PAPER_CODE" AND                                                                                                                                                                                             
                  "CEA"."ELEMENT"='Moderation of IA')                                                                                                                                                                                                                                                           
           filter(("CEA"."ELEMENT"='Moderation of IA' AND (:V_PADDED_EXAMINER_CODE IS NULL OR                                                                                                                                                                                                                   
                  "EXAMINER_CODE"=:V_PADDED_EXAMINER_CODE)))                                                                                                                                                                                                                                                    
      18 - access("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE")                                                                                                                                                                                                                                               
           filter("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE")                                                                                                                                                                                                                                               
      21 - access("WFI"."INSTANCE_ID"="IA1"."WORKFLOW_INSTANCE_ID")                                                                                                                                                                                                                                             
      22 - filter(("IA1"."MONTH"=:V_MONTH AND "IA1"."YEAR"=TO_NUMBER(:V_YEAR)))                                                                                                                                                                                                                                 
      24 - filter((:V_EXAMINER_NAME IS NULL OR UPPER("TITLE"||' '||"FIRSTNAME"||' '||"LASTNAME") LIKE :V_SEARCH_EXAMINER_NAME))                                                                                                                                                                                 
      25 - access("EXNAME"."EXAMINER_CODE"="PERSON_CODE")                                                                                                                                                                                                                                                       
    66 rows selected

  • Need a help to write the query

    Hi,
    I need a small help to write the query.
    I have a table contains couponid,coupon,createdate,expirationdate,assigndate from couponday table
    i want to write the query to select the coupon whose Expiry date in the table is NOT within 30 days.
    Thanks in advance

    Hi,
    user586 wrote:
    i want to write the query to select the coupon whose Expiry date in the table is NOT within 30 days.If you mean expirationdate (datatype: DATE) is not within 30 days (past or future) of run time, then:
    SELECT  coupon          -- or whatever columns you want
    FROM    table_x
    WHERE   expirationdate  NOT BETWEEN  SYSDATE - 30
                                AND      SYSDATE + 30
    ;

  • Please help!!! Tuning the query

    Hi,
    I am using Oracle BDBXML 2.4.16. In the following, policyContainer.dbxml has around 1000 documents and productsContainer.dbxml around 10 documents. The following query is taking around 6 - 8 seconds to fetch the data of around 300 records. I have created node-element-equality-string indexes on PolicyEvent, PolicyStatus, Archived, IsLatest, ProductID and CompanyID.
    I am novice on Query tuning. Can someone please help me to tune the following query. I have posted the query plan as well.
    Thanks in Advance!!
    Balakrishna.
    Query:
    query ' for $policy in collection("policyContainer.dbxml")/Policy[PolicyState/PolicyEvent=("APPLICATION","QUOTE","BINDER","POLICY","ENDORSEMENT QUOTE")]
    [PolicyHeader/ProductID = (for $product in collection("productsContainer.dbxml")/Product/ProductsHeader[CompanyID=(1)] return $product/ProductID)]
    [PolicyState/PolicyStatus !=("RATE","DECLINED ENDORSEMENT QUOTE","DECLINED NON-PRE ENDORSEMENT QUOTE","DECLINED EXTENSION QUOTE")]
    [PolicyState/Archived !="true"]
    [(PolicyState/IsLatest !="false"
    and (PolicyState/PolicyStatus != ("ENDORSEMENT QUOTE","NON-PRE ENDORSEMENT QUOTE","EXTENSION QUOTE")))
    or (PolicyState/IsLatest !="true"
    and (PolicyState/PolicyStatus =("ENDORSEMENT QUOTE","NON-PRE ENDORSEMENT QUOTE","EXTENSION QUOTE")))]
    let $state := $policy/PolicyState 
    let $header := $policy/PolicyHeader
    let $datatable := $policy/DataTable/DataTableInfo
    return
    <policyDetail>
    {$policy/SubmissionNumber},
    {$policy/DocumentNumber},
    {$policy/QuoteVersionNumber},
    {$state/*,$header/*,$datatable/*}
    </policyDetail>'
    Query plan:
    <XQuery>
      <Return>
        <LetTuple uri="" name="datatable">
          <LetTuple uri="" name="header">
            <LetTuple uri="" name="state">
              <ForTuple uri="" name="policy">
                <ContextTuple/>
                <QueryPlanToAST>
                  <BufferQP id="2">
                    <NegativeNodePredicateFilterQP uri="" name="#tmp67">
                      <NegativeNodePredicateFilterQP uri="" name="#tmp73">
                        <NodePredicateFilterQP uri="" name="#tmp404">
                          <ParentOfChildJoinQP>
                            <StepQP axis="parent-of-child" name="PolicyState" nodeType="element">
                              <UnionQP>
                                <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyEvent" value="ENDORSEMENT QUOTE"/>
                                <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyEvent" value="APPLICATION"/>
                                <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyEvent" value="POLICY"/>
                                <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyEvent" value="BINDER"/>
                                <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyEvent" value="QUOTE"/>
                              </UnionQP>
                            </StepQP>
                            <StepQP axis="child" name="Policy" nodeType="element">
                              <SequentialScanQP container="policyContainer.dbxml" nodeType="document"/>
                            </StepQP>
                          </ParentOfChildJoinQP>
                          <ValueFilterQP comparison="eq" general="true">
                            <StepQP axis="child" name="ProductID" nodeType="element">
                              <StepQP axis="child" name="PolicyHeader" nodeType="element">
                                <VariableQP name="#tmp404"/>
                              </StepQP>
                            </StepQP>
                            <Atomize>
                              <Return>
                                <ForTuple uri="" name="product">
                                  <ContextTuple/>
                                  <QueryPlanToAST>
                                    <ParentOfChildJoinQP>
                                      <ValueFilterQP comparison="eq" general="true">
                                        <PresenceQP container="productsContainer.dbxml" index="node-element-equality-string" operation="prefix" child="CompanyID"/>
                                        <Sequence>
                                          <NumericTypeConstructor value="1.0E0" typeuri="http://www.w3.org/2001/XMLSchema" typename="integer"/>
                                        </Sequence>
                                      </ValueFilterQP>
                                      <StepQP axis="child" name="ProductsHeader" nodeType="element">
                                        <StepQP axis="child" name="Product" nodeType="element">
                                          <SequentialScanQP container="productsContainer.dbxml" nodeType="document"/>
                                        </StepQP>
                                      </StepQP>
                                    </ParentOfChildJoinQP>
                                  </QueryPlanToAST>
                                </ForTuple>
                                <QueryPlanToAST>
                                  <StepQP axis="child" name="ProductID" nodeType="element">
                                    <VariableQP name="product"/>
                                  </StepQP>
                                </QueryPlanToAST>
                              </Return>
                            </Atomize>
                          </ValueFilterQP>
                        </NodePredicateFilterQP>
                        <ValueFilterQP comparison="ne" general="true">
                          <ValueFilterQP comparison="ne" general="true">
                            <ValueFilterQP comparison="ne" general="true">
                              <ValueFilterQP comparison="ne" general="true">
                                <StepQP axis="child" name="PolicyStatus" nodeType="element">
                                  <StepQP axis="child" name="PolicyState" nodeType="element">
                                    <VariableQP name="#tmp73"/>
                                  </StepQP>
                                </StepQP>
                                <Sequence>
                                  <AnyAtomicTypeConstructor value="RATE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                  <AnyAtomicTypeConstructor value="DECLINED ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                  <AnyAtomicTypeConstructor value="DECLINED NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                  <AnyAtomicTypeConstructor value="DECLINED EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                </Sequence>
                              </ValueFilterQP>
                              <Sequence>
                                <AnyAtomicTypeConstructor value="RATE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                <AnyAtomicTypeConstructor value="DECLINED ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                <AnyAtomicTypeConstructor value="DECLINED NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                <AnyAtomicTypeConstructor value="DECLINED EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              </Sequence>
                            </ValueFilterQP>
                            <Sequence>
                              <AnyAtomicTypeConstructor value="RATE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              <AnyAtomicTypeConstructor value="DECLINED ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              <AnyAtomicTypeConstructor value="DECLINED NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              <AnyAtomicTypeConstructor value="DECLINED EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            </Sequence>
                          </ValueFilterQP>
                          <Sequence>
                            <AnyAtomicTypeConstructor value="RATE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            <AnyAtomicTypeConstructor value="DECLINED ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            <AnyAtomicTypeConstructor value="DECLINED NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            <AnyAtomicTypeConstructor value="DECLINED EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                          </Sequence>
                        </ValueFilterQP>
                      </NegativeNodePredicateFilterQP>
                      <ChildJoinQP>
                        <StepQP axis="child" name="PolicyState" nodeType="element">
                          <VariableQP name="#tmp67"/>
                        </StepQP>
                        <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="Archived" value="true"/>
                      </ChildJoinQP>
                    </NegativeNodePredicateFilterQP>
                    <UnionQP>
                      <NegativeNodePredicateFilterQP uri="" name="#tmp18">
                        <NegativeNodePredicateFilterQP uri="" name="#tmp46">
                          <BufferReferenceQP id="2"/>
                          <ChildJoinQP>
                            <StepQP axis="child" name="PolicyState" nodeType="element">
                              <VariableQP name="#tmp46"/>
                            </StepQP>
                            <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="IsLatest" value="false"/>
                          </ChildJoinQP>
                        </NegativeNodePredicateFilterQP>
                        <ValueFilterQP comparison="ne" general="true">
                          <ValueFilterQP comparison="ne" general="true">
                            <ValueFilterQP comparison="ne" general="true">
                              <StepQP axis="child" name="PolicyStatus" nodeType="element">
                                <StepQP axis="child" name="PolicyState" nodeType="element">
                                  <VariableQP name="#tmp18"/>
                                </StepQP>
                              </StepQP>
                              <Sequence>
                                <AnyAtomicTypeConstructor value="ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                <AnyAtomicTypeConstructor value="NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                                <AnyAtomicTypeConstructor value="EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              </Sequence>
                            </ValueFilterQP>
                            <Sequence>
                              <AnyAtomicTypeConstructor value="ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              <AnyAtomicTypeConstructor value="NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                              <AnyAtomicTypeConstructor value="EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            </Sequence>
                          </ValueFilterQP>
                          <Sequence>
                            <AnyAtomicTypeConstructor value="ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            <AnyAtomicTypeConstructor value="NON-PRE ENDORSEMENT QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                            <AnyAtomicTypeConstructor value="EXTENSION QUOTE" typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
                          </Sequence>
                        </ValueFilterQP>
                      </NegativeNodePredicateFilterQP>
                      <NegativeNodePredicateFilterQP uri="" name="#tmp56">
                        <ParentOfChildJoinQP>
                          <StepQP axis="parent-of-child" name="PolicyState" nodeType="element">
                            <UnionQP>
                              <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyStatus" value="NON-PRE ENDORSEMENT QUOTE"/>
                              <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyStatus" value="EXTENSION QUOTE"/>
                              <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="PolicyStatus" value="ENDORSEMENT QUOTE"/>
                            </UnionQP>
                          </StepQP>
                          <BufferReferenceQP id="2"/>
                        </ParentOfChildJoinQP>
                        <ChildJoinQP>
                          <StepQP axis="child" name="PolicyState" nodeType="element">
                            <VariableQP name="#tmp56"/>
                          </StepQP>
                          <ValueQP container="policyContainer.dbxml" index="node-element-equality-string" operation="eq" child="IsLatest" value="true"/>
                        </ChildJoinQP>
                      </NegativeNodePredicateFilterQP>
                    </UnionQP>
                  </BufferQP>
                </QueryPlanToAST>
              </ForTuple>
              <QueryPlanToAST>
                <StepQP axis="child" name="PolicyState" nodeType="element">
                  <VariableQP name="policy"/>
                </StepQP>
              </QueryPlanToAST>
            </LetTuple>
            <QueryPlanToAST>
              <StepQP axis="child" name="PolicyHeader" nodeType="element">
                <VariableQP name="policy"/>
              </StepQP>
            </QueryPlanToAST>
          </LetTuple>
          <QueryPlanToAST>
            <StepQP axis="child" name="DataTableInfo" nodeType="element">
              <StepQP axis="child" name="DataTable" nodeType="element">
                <VariableQP name="policy"/>
              </StepQP>
            </StepQP>
          </QueryPlanToAST>
        </LetTuple>
        <DOMConstructor type="element">
          <Name>
            <Sequence>
              <ATQNameConstructor uri="" prefix="" localname="policyDetail" typeuri="http://www.w3.org/2001/XMLSchema" typename="QName"/>
            </Sequence>
          </Name>
          <Children>
            <ContentSequence>
              <QueryPlanToAST>
                <StepQP axis="child" name="SubmissionNumber" nodeType="element">
                  <VariableQP name="policy"/>
                </StepQP>
              </QueryPlanToAST>
            </ContentSequence>
            <ContentSequence>
              <Sequence>
                <AnyAtomicTypeConstructor value="," typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
              </Sequence>
            </ContentSequence>
            <ContentSequence>
              <QueryPlanToAST>
                <StepQP axis="child" name="DocumentNumber" nodeType="element">
                  <VariableQP name="policy"/>
                </StepQP>
              </QueryPlanToAST>
            </ContentSequence>
            <ContentSequence>
              <Sequence>
                <AnyAtomicTypeConstructor value="," typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
              </Sequence>
            </ContentSequence>
            <ContentSequence>
              <QueryPlanToAST>
                <StepQP axis="child" name="QuoteVersionNumber" nodeType="element">
                  <VariableQP name="policy"/>
                </StepQP>
              </QueryPlanToAST>
            </ContentSequence>
            <ContentSequence>
              <Sequence>
                <AnyAtomicTypeConstructor value="," typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
              </Sequence>
            </ContentSequence>
            <ContentSequence>
              <Parenthesized>
                <QueryPlanToAST>
                  <ChildJoinQP>
                    <VariableQP name="state"/>
                    <SequentialScanQP container="policyContainer.dbxml" nodeType="element"/>
                  </ChildJoinQP>
                </QueryPlanToAST>
                <QueryPlanToAST>
                  <StepQP axis="child" uri="*" name="*" nodeType="element">
                    <VariableQP name="header"/>
                  </StepQP>
                </QueryPlanToAST>
                <QueryPlanToAST>
                  <ChildJoinQP>
                    <VariableQP name="datatable"/>
                    <SequentialScanQP container="policyContainer.dbxml" nodeType="element"/>
                  </ChildJoinQP>
                </QueryPlanToAST>
              </Parenthesized>
            </ContentSequence>
          </Children>
        </DOMConstructor>
      </Return>
    </XQuery>

    The good news is that your indexes are being used (anywhere in the query plan where you see index="node-element-equality-string"), the bad news is that the entire policyContainer is being scanned several times (<SequentialScanQP container="policyContainer.dbxml" nodeType="element"/>). Your best bet is to upgrade to dbxml-2.5.16, since that has several improvements to the optimizer that should optimize away those scans. Failing that, use the shell command (dbxml) to add and remove indexes and see how that changes the query plan and speed. The following line is what is causing the scans:
    {$state/*,$header/*,$datatable/*}So add indexes that will help to locate those nodes, or change that line so that the query is faster.
    Lauren Foutz

  • Tuning the query : Very Urgent

    Hi
    We have query wich needs tuning.when we are putting REGULAR EXPRESSION query is running fine but whne we put like LIKE stmt it is taking time.Here is the query below.Please help on tuning.
    SELECT a.order_number, b.last_update_date,TO_CHAR( b.split_percent,'FM99999.009') SPLIT_PERCENTAGE,
    rs.NAME " SALES_PERSON_NAME ", rs.salesrep_number, b.effective_date,
    b.creation_date "CREATION_DATE", rt.NAME "TERRITORY_NAME",
    rt.segment1 "ERP_CODE", a.booked_date "DATE_BOOKED",
    TO_CHAR(ROUND((( (SELECT SUM (ordered_quantity * unit_selling_price)
    FROM apps.oe_order_lines_all ol
    WHERE ol.header_id = a.header_id)
    * b.split_percent
    / 100
    ) , 2),'FM99999999999999999999.009') order_total ,
    (SELECT user_name
    FROM fnd_user
    WHERE user_id = b.last_updated_by) requested_by,
    b.obsolete_date
    FROM oe_order_headers_all a,
    apps.csm_header_sales_cr_hist b,
    jtf_rs_salesreps rs,
    ra_territories rt
    WHERE 1 = 1
    AND a.header_id = b.source_header_id
    AND b.territory_id = rt.territory_id
    AND b.salesrep_id = rs.salesrep_id
    AND b.source_type = 'O'
    AND a.order_number IN (
    SELECT a.order_number
    FROM oe_order_headers_all a,
    apps.csm_header_sales_cr_hist b,
    jtf_rs_salesreps rs,
    ra_territories rt
    WHERE 1 = 1
    AND a.header_id = b.source_header_id
    AND b.territory_id = rt.territory_id
    AND b.salesrep_id = rs.salesrep_id
    AND b.source_type = 'O'
    -- AND b.obsolete_date IS NULL --ommented by andondap as per TD#9648 Changes
    AND  REGEXP_LIKE ( rs.name , '(svc)|(Muti.*Y)|(Multi.*Y)|(._MY)')  Commented by andondap as per TD#9648 Changes
    AND b.last_update_date BETWEEN TO_DATE ('2012/11/25', 'YYYY/MM/DD') AND TO_DATE ('2013/03/23', 'YYYY/MM/DD')+ 0.9999
    AND REGEXP_LIKE ( rs.name,'(.MY)|(Muti.*Y))|(Multi.*Y)|(._MY) |(mlti)')
    AND rs.name LIKE '%SVC%MULTI%' OR rs.name NOT LIKE '%DUMMY%' OR rs.name LIKE 'Svc%Multi%' OR rs.name LIKE 'Svc%MY%'
    OR rs.name LIKE 'Service%Multi%' OR rs.name LIKE '%MY_SHARE_TM' OR rs.name LIKE '%MY_SHARE_T')
    ORDER BY a.order_number, b.creation_date
    Thanks
    Hibin

    Hmmm, let's see...
    1. OP provided formatted code using {noformat}{noformat} tags.... - FAILED
    2. OP provided database version in full... - FAILED
    3. OP provided table structures and index information... - FAILED
    4. OP provided cardinality and selectivity information... - FAILED
    5. OP provided explain plans... - FAILED
    6. OP provided execution traces... - FAILED
    7. OP is a new member and can be excused for above failures... - FAILED
    8. OP has asked previous questions and followed forum etiquette by marking them as answered... - FAILED
    9. OP has respected volunteers and other questioners by not marking his question as Urgent... - FAILED
    10. OP has read the forum FAQ ({message:id=9360002}) for posting his question...  - FAILED
    11. OP has read the forum FAQ ({message:id=9360003}) for posting a tuning question... - FAILED
    It's a good job you're not a computer program, you wouldn't have even compiled.
    so, points to note:
    This is a forum of volunteers.  There's no such thing as an Urgent question here, and it's considered rude to suggest your question is urgent, as that indicates you want immediate attention from the people who are giving up their own time to help, and who have their own jobs to do.  It's also rude for the other people who are asking questions, as everyone would like an answer to their problem as soon as possible, so what makes you any more special?  An urgent issue is one where a live system is down potentially putting people's lives at risk or causing a company to lose money, or somehow damage their services.  Such issues should be logged with Oracle Support, not on the free OTN forums.
    Next, when you post your question, ensure you provide all the information that is needed for people to be able to help you.  Read the FAQ posts which point to useful threads indicating what information is required, especially for tuning requests.
    Finally, when your questions have been answered, it is common courtesy to mark them as answered (and award points if appropriate), otherwise it indicates that you have no respect for the people who are helping you.
    If you follow all the advice above, you will end up creating a good question that people will be willing to help you with.   If you don't follow the advice above, such as in this question you've posted, you will find that few experts will bother to help (or if they post it will not likely be helpful advise you receive).  The choice is yours.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Help Required(Rewriting the query to reduce steps)

    With and Without Group ID,I am populating a value into a column,Can anyone please help to write the same query in an other way.This is a sample column.Likewise,there are 5 more columns to be populated.So that I have to write 2 left outer joins for a single column with a little difference.
    SELECT
    CASE
         WHEN T6.ACTUAL_FUNCTION IS NOT NULL
         THEN T6.ACTUAL_FUNCTION
         WHEN T10.ACTUAL_FUNCTION IS NOT NULL
         THEN T10.ACTUAL_FUCNTION
              ELSE T5.ACTUAL_FUCNTION
    END AF_NOM_PRE_GTEES
    FROM
    ABC_WT17 T1
         INNER JOIN
         ABC_CUSTOMER_WT01 T3
         ON T1.ORIGINAL_SDS_PARTY_IDR=T3.ORIGINAL_SDS_PARTY_IDR
         AND T1.IDR_TYPE_CODE=T3.IDR_TYPE_CODE
         LEFT OUTER JOIN /* This is the condition with group ID*/
         RESIDUAL_CONTROL T6
         ON
         T1.NOM_PRE_GTEES = T6.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T6.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T6.VALUE_MAX
         AND
    _     T1.GROUP_ID = T6.GROUP_ID_
         AND
         T6.FALLBACK_IND = ‘N’
    LEFT OUTER JOIN /* this is the condition without Group ID*/
         RESIDUAL_CONTROL T10
         ON
         T1.NOM_PRE_GTEES = T10.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T10.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T10.VALUE_MAX
         AND
         T10.FALLBACK_IND = ‘N’
         CROSS JOIN
         RESIDUAL_CONTROL T5
         ON T5.FALLBACK_IND = ‘Y’
    Thanks in advance.

    KVB wrote:
    With and Without Group ID,I am populating a value into a column,Can anyone please help to write the same query in an other way.This is a sample column.Likewise,there are 5 more columns to be populated.So that I have to write 2 left outer joins for a single column with a little difference.
    SELECT
    CASE
         WHEN T6.ACTUAL_FUNCTION IS NOT NULL
         THEN T6.ACTUAL_FUNCTION
         WHEN T10.ACTUAL_FUNCTION IS NOT NULL
         THEN T10.ACTUAL_FUCNTION
              ELSE T5.ACTUAL_FUCNTION
    END AF_NOM_PRE_GTEES
    FROM
    ABC_WT17 T1
         INNER JOIN
         ABC_CUSTOMER_WT01 T3
         ON T1.ORIGINAL_SDS_PARTY_IDR=T3.ORIGINAL_SDS_PARTY_IDR
         AND T1.IDR_TYPE_CODE=T3.IDR_TYPE_CODE
         LEFT OUTER JOIN /* This is the condition with group ID*/
         RESIDUAL_CONTROL T6
         ON
         T1.NOM_PRE_GTEES = T6.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T6.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T6.VALUE_MAX
         AND
    _     T1.GROUP_ID = T6.GROUP_ID_
         AND
         T6.FALLBACK_IND = ‘N’
    LEFT OUTER JOIN /* this is the condition without Group ID*/
         RESIDUAL_CONTROL T10
         ON
         T1.NOM_PRE_GTEES = T10.VALUE_MAX
         OR
         T1.NOM_PRE_GTEES > T10.VALUE_GREATER_THAN
         AND
         T1.NOM_PRE_GTEES < T10.VALUE_MAX
         AND
         T10.FALLBACK_IND = ‘N’
         CROSS JOIN
         RESIDUAL_CONTROL T5
         ON T5.FALLBACK_IND = ‘Y’
    Thanks in advance.Thread: HOW TO: Post a SQL statement tuning request - template posting
    HOW TO: Post a SQL statement tuning request - template posting

  • Need help in writing the query

    The initial data is as follows:
    ID PARENT_ID
    =============
    1 NULL
    2 NULL
    3 2
    4 6
    5 3
    6 7
    7 4
    8 NULL
    but output is as follows in such way that Parent_Id should be displayed in ID place
    ID PARENT_ID
    =============
    1 NULL
    2 NULL
    3 2
    8 NULL
    6 8
    4 6
    5 3
    7 4
    Can any one help how resolve this query?
    Thanks in advance

    Your output is inconsistent with initial data :) But
    select * from t start with parent_id is null connect by parent_id = prior id;

  • Need help in highlighting the query text in document

    Hi, I am trying to load the files in the blob column and trying to create the text index on it.
    i need to query the blob column in the document table with a string, which needs to return the relevant documents with the query string highlighted with some color.
    Can you please help me with an example on the above.
    Thanks in advance.

    SCOTT@orcl_11gR2> -- table:
    SCOTT@orcl_11gR2> CREATE TABLE document_tab
      2    (document_col  BLOB)
      3  /
    Table created.
    SCOTT@orcl_11gR2> -- procedure to load documents:
    SCOTT@orcl_11gR2> CREATE OR REPLACE PROCEDURE load_document
      2    (p_dir  IN VARCHAR2,
      3       p_file IN VARCHAR2)
      4  AS
      5    v_blob       BLOB;
      6    v_bfile       BFILE;
      7  BEGIN
      8    INSERT INTO document_tab (document_col)
      9    VALUES (EMPTY_BLOB())
    10    RETURNING document_col INTO v_blob;
    11    v_bfile := BFILENAME (UPPER (p_dir), p_file);
    12    DBMS_LOB.FILEOPEN (v_bfile, DBMS_LOB.LOB_READONLY);
    13    DBMS_LOB.LOADFROMFILE (v_blob, v_bfile, DBMS_LOB.GETLENGTH (v_bfile));
    14    DBMS_LOB.FILECLOSE (v_bfile);
    15  END load_document;
    16  /
    Procedure created.
    SCOTT@orcl_11gR2> SHOW ERRORS
    No errors.
    SCOTT@orcl_11gR2> -- load documents (directory and files must be on server, not client):
    SCOTT@orcl_11gR2> CREATE OR REPLACE DIRECTORY my_dir AS 'c:\my_oracle_files'
      2  /
    Directory created.
    SCOTT@orcl_11gR2> BEGIN
      2    load_document ('my_dir', 'banana.pdf');
      3    load_document ('my_dir', 'english.doc');
      4    load_document ('my_dir', 'sample.txt');
      5  END;
      6  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> -- confirm files were loaded:
    SCOTT@orcl_11gR2> SELECT DBMS_LOB.GETLENGTH (document_col)
      2  FROM   document_tab
      3  /
    DBMS_LOB.GETLENGTH(DOCUMENT_COL)
                              222824
                               22016
                                  60
    3 rows selected.
    SCOTT@orcl_11gR2> -- text index:
    SCOTT@orcl_11gR2> CREATE INDEX document_idx
      2  ON document_tab (document_col)
      3  INDEXTYPE IS CTXSYS.CONTEXT
      4  /
    Index created.
    SCOTT@orcl_11gR2> -- confirm files were indexed:
    SCOTT@orcl_11gR2> SELECT COUNT(*) FROM dr$document_idx$i
      2  /
      COUNT(*)
           319
    1 row selected.
    SCOTT@orcl_11gR2> -- function to return highlighted document:
    SCOTT@orcl_11gR2> CREATE OR REPLACE FUNCTION your_markup
      2    (p_index_name IN VARCHAR2,
      3       p_textkey    IN VARCHAR2,
      4       p_text_query IN VARCHAR2,
      5       p_plaintext  IN BOOLEAN  DEFAULT TRUE,
      6       p_tagset     IN VARCHAR2 DEFAULT 'HTML_DEFAULT',
      7       p_starttag   IN VARCHAR2 DEFAULT '*',
      8       p_endtag     IN VARCHAR2 DEFAULT '*',
      9       p_key_type   IN VARCHAR2 DEFAULT 'ROWID')
    10    RETURN          CLOB
    11  AS
    12    v_clob          CLOB;
    13  BEGIN
    14    CTX_DOC.SET_KEY_TYPE (p_key_type);
    15    CTX_DOC.MARKUP
    16        (index_name => p_index_name,
    17         textkey    => p_textkey,
    18         text_query => p_text_query,
    19         restab     => v_clob,
    20         plaintext  => p_plaintext,
    21         tagset     => p_tagset,
    22         starttag   => p_starttag,
    23         endtag     => p_endtag);
    24    RETURN v_clob;
    25  END your_markup;
    26  /
    Function created.
    SCOTT@orcl_11gR2> SHOW ERRORS
    No errors.
    SCOTT@orcl_11gR2> -- query that returns highlighted document:
    SCOTT@orcl_11gR2> VARIABLE string VARCHAR2(100)
    SCOTT@orcl_11gR2> EXEC :string := 'test AND demonstration'
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> SELECT your_markup ('document_idx', ROWID, :string)
      2           AS highlighted_text
      3  FROM   document_tab
      4  WHERE  CONTAINS (document_col, :string) > 0
      5  /HIGHLIGHTED_TEXT
    This is a test document for demonstration of highlighting.
    1 row selected.
    SCOTT@orcl_11gR2>

  • Help in generating the query

    Hi All,
    I have the below requirement.
    Master table:
    Product ID      Product Name
    1               TV
    2               Cellphone
    3               Laptop
    4               DVD Player
    Details table:
    Product ID     Spec type     Spec Detail
    1               Color          Blue
    1               Weight          20
    2               Color          Blue
    2               Weight          20
    3               Color          Blue
    3                Weight          25
    4               Color          Blue
    4               Weight          20
    4               Height          10Im looking for a way to identify the products that has exact same specifications.
    ie., in the above example TV and Cellphone has the exact specifications.
    So the output of the query should be TV and Cellphone here.
    Is it possible to do in a query or we need to have some sql block to perform this action.
    Any help would be greatly appreciated.
    Thanks,
    Agathya

    Hi agathya,
    We don't know how you would like to handle the situation where more than two products have the same specifications, so I extended your sample data a bit to reflect that situation as well:
    SQL> create table products (id,name)
      2  as
      3  select 1, 'TV' from dual union all
      4  select 2, 'Cellphone' from dual union all
      5  select 3, 'Laptop' from dual union all
      6  select 4, 'DVD Player' from dual union all
      7  select 5, 'Radio' from dual union all
      8  select 6, 'VCR' from dual
      9  /
    Tabel is aangemaakt.
    SQL> create table product_specifications (product_id,spec_type,spec_detail)
      2  as
      3  select 1, 'Color' , 'Blue' from dual union all
      4  select 1, 'Weight', '20'   from dual union all
      5  select 2, 'Color' , 'Blue' from dual union all
      6  select 2, 'Weight', '20'   from dual union all
      7  select 3, 'Color' , 'Blue' from dual union all
      8  select 3, 'Weight', '25'   from dual union all
      9  select 4, 'Color' , 'Blue' from dual union all
    10  select 4, 'Weight', '20'   from dual union all
    11  select 4, 'Height', '10'   from dual union all
    12  select 5, 'Color' , 'Blue' from dual union all
    13  select 5, 'Weight', '20'   from dual union all
    14  select 6, 'Color' , 'Blue' from dual union all
    15  select 6, 'Weight', '20'   from dual union all
    16  select 6, 'Height', '10'   from dual
    17  /
    Tabel is aangemaakt.
    SQL> select p1.name
      2       , p2.name
      3    from products p1
      4       , products p2
      5       , product_specifications ps1
      6       , product_specifications ps2
      7   where p1.id = ps1.product_id
      8     and p2.id = ps2.product_id
      9     and p1.id < p2.id
    10   group by p1.id
    11       , p1.name
    12       , p2.id
    13       , p2.name
    14  having sqrt(count(*)) =
    15         count(case when ps1.spec_type = ps2.spec_type and ps1.spec_detail = ps2.spec_detail then 1 end)
    16  /
    NAME       NAME
    TV         Cellphone
    TV         Radio
    Cellphone  Radio
    DVD Player VCR
    4 rijen zijn geselecteerd.But why on earth did you or your predecessor model product specifications like this? You are making it far more complicated than it needs to be. And the datatype of height and weight should not be the same as for color. But now they are. And how do you restrict the allowable values for colors? Color, weight and height are attributes of your products so they should have been modeled like that.
    See how easy your questions becomes after remodeling it:
    SQL> drop table product_specifications purge
      2  /
    Tabel is verwijderd.
    SQL> drop table products purge
      2  /
    Tabel is verwijderd.
    SQL> create table products (id,name,color,weight,height)
      2  as
      3  select 1, 'TV', 'Blue', 20, null from dual union all
      4  select 2, 'Cellphone', 'Blue', 20, null from dual union all
      5  select 3, 'Laptop', 'Blue', 25, null from dual union all
      6  select 4, 'DVD Player', 'Blue', 20, 10 from dual union all
      7  select 5, 'Radio', 'Blue', 20, null from dual union all
      8  select 6, 'VCR', 'Blue', 20, 10 from dual
      9  /
    Tabel is aangemaakt.
    SQL> select * from products
      2  /
            ID NAME       COLO     WEIGHT     HEIGHT
             1 TV         Blue         20
             2 Cellphone  Blue         20
             3 Laptop     Blue         25
             4 DVD Player Blue         20         10
             5 Radio      Blue         20
             6 VCR        Blue         20         10
    6 rijen zijn geselecteerd.
    SQL> select p1.name
      2       , p2.name
      3    from products p1
      4       , products p2
      5   where p1.id < p2.id
      6     and ( p1.color = p2.color or (p1.color is null and p2.color is null))
      7     and ( p1.weight = p2.weight or (p1.weight is null and p2.weight is null))
      8     and ( p1.height = p2.height or (p1.height is null and p2.height is null))
      9  /
    NAME       NAME
    TV         Cellphone
    TV         Radio
    Cellphone  Radio
    DVD Player VCR
    4 rijen zijn geselecteerd.Hope this helps.
    Regards,
    Rob.

  • Help in correcting the query

    Hi,
    I have below query:
    select u.v_um_code,v_um_name,count(f.v_fc_code), count(s.n_sl_no), count(distinct s.n_agent_no)
    from subm_buss_um_master u,subm_buss_fc_master f,submitted_business_raw s
    where u.v_um_code=f.v_um_code and f.v_fc_code=s.n_agent_no
    and f.v_status='A' and u.v_status='A'
    and trunc(d_submitted) between '01-JUL-2004' AND '31-JUL-2004'
    group by u.v_um_code,v_um_name;
    the output should be such that first all the records should be fetched from subm_buss_um_master table (where u.v_status='A')--> then count(f.v_fc_code) then -->count(s.n_sl_no), count(distinct s.n_agent_no)
    the data/columns in these tables is large, I cannot paste here.
    Thanks in advance
    Tariq.

    Hi,
    If SET operator UNION helps then great!!!
    For example: As per my requirement, first all employees and sum of salary.....is the query.
    SELECT ename, sal FROM emp
    UNION
    SELECT 'Grand Total ', SUM(sal) FROM emp
    ORDER BY sal;
    Regards,
    Sailaja

  • Help in rewrite the Query

    Hello
    I have one query taking time to fetch the records. Table contains just 40,000 thousands records but lots of case statement in the query, I just remove lots of case statement there are lot more...
    Can you please help me out to rewrite the query to fetch the records faster. Also Right now there are no indexes on the table....
    SELECT O.cn,
           O.BEN_LAST_NAME,
           O.BEN_FIRST_NAME,
           O.BEN_MI,
           O.SSN,
           O.DOB,
           O.SEX,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 00 AND 34 THEN
               1
              ELSE
               0
           END AS AGE_GROUP0_34_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 35 AND 44 THEN
               1
              ELSE
               0
           END AS AGE_GROUP35_44_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 45 AND 54 THEN
               1
              ELSE
               0
           END AS AGE_GROUP45_54_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 55 AND 59 THEN
               1
              ELSE
               0
           END AS AGE_GROUP55_59_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 60 AND 64 THEN
               1
              ELSE
               0
           END AS AGE_GROUP60_64_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 65 AND 69 THEN
               1
              ELSE
               0
           END AS AGE_GROUP65_69_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 70 AND 74 THEN
               1
              ELSE
               0
           END AS AGE_GROUP70_74_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 75 AND 79 THEN
               1
              ELSE
               0
           END AS AGE_GROUP75_79_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 80 AND 84 THEN
               1
              ELSE
               0
           END AS AGE_GROUP80_84_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 85 AND 89 THEN
               1
              ELSE
               0
           END AS AGE_GROUP85_89_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 90 AND 94 THEN
               1
              ELSE
               0
           END AS AGE_GROUP90_94_F,
           CASE
              WHEN O.SEX = 'F' AND O.AGE BETWEEN 95 AND 00 THEN
               1
              ELSE
               0
           END AS AGE_GROUP95_GT_F,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 00 AND 34 THEN
               1
              ELSE
               0
           END AS AGE_GROUP0_34_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 35 AND 44 THEN
               1
              ELSE
               0
           END AS AGE_GROUP35_44_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 45 AND 54 THEN
               1
              ELSE
               0
           END AS AGE_GROUP45_54_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 45 AND 59 THEN
               1
              ELSE
               0
           END AS AGE_GROUP55_59_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 60 AND 64 THEN
               1
              ELSE
               0
           END AS AGE_GROUP60_64_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 65 AND 69 THEN
               1
              ELSE
               0
           END AS AGE_GROUP65_69_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 70 AND 74 THEN
               1
              ELSE
               0
           END AS AGE_GROUP70_74_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 75 AND 79 THEN
               1
              ELSE
               0
           END AS AGE_GROUP75_79_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 80 AND 84 THEN
               1
              ELSE
               0
           END AS AGE_GROUP80_84_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 85 AND 89 THEN
               1
              ELSE
               0
           END AS AGE_GROUP85_89_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 90 AND 94 THEN
               1
              ELSE
               0
           END AS AGE_GROUP90_94_M,
           CASE
              WHEN O.SEX = 'M' AND O.AGE BETWEEN 95 AND 00 THEN
               1
              ELSE
               0
           END AS AGE_GROUP95_GT_M,
           O.YEAR,
          CASE WHEN EXISTS (SELECT m1.hcc_model_category1 FROM HCC_MODEL_DIAGNOSIS M1 , HCC_MODEL_DIAGNOSIS_MAPPING HM
                            ,mor222 m2 WHERE m1.map_id = hm.map_id_ref
                            AND m2.YEAR = hm.YEAR
                            AND o.cn = m2.cn
                            AND o.YEAR = hm.YEAR
                            AND m1.hcc_model_category1 = 1
                            AND m2.diag_code = m1.icd9cmscode) THEN 1 ELSE 0 END AS DISEASE_COEF_HCC1,
          CASE WHEN EXISTS (SELECT m1.hcc_model_category1 FROM HCC_MODEL_DIAGNOSIS M1 , HCC_MODEL_DIAGNOSIS_MAPPING HM
                            ,mor222 m2 WHERE m1.map_id = hm.map_id_ref
                            AND m2.YEAR = hm.YEAR
                            AND o.cn = m2.cn
                            AND o.YEAR = hm.YEAR
                            AND m1.hcc_model_category1 = 2
                            AND m2.diag_code = m1.icd9cmscode) THEN 1 ELSE 0 END AS DISEASE_COEF_HCC2,
           CASE WHEN EXISTS (SELECT m1.hcc_model_category1 FROM HCC_MODEL_DIAGNOSIS M1 , HCC_MODEL_DIAGNOSIS_MAPPING HM
                            ,mor222 m2 WHERE m1.map_id = hm.map_id_ref
                            AND m2.YEAR = hm.YEAR
                            AND o.cn = m2.cn
                            AND o.YEAR = hm.YEAR
                            AND m1.hcc_model_category1 = 5
                             AND m2.diag_code = m1.icd9cmscode) THEN 1 ELSE 0 END AS       DISEASE_COEF_HCC5,
            CASE WHEN EXISTS (SELECT m1.hcc_model_category1 FROM HCC_MODEL_DIAGNOSIS M1 , HCC_MODEL_DIAGNOSIS_MAPPING HM
                            ,mor222 m2 WHERE m1.map_id = hm.map_id_ref
                            AND m2.YEAR = hm.YEAR
                            AND o.cn = m2.cn
                            AND o.YEAR = hm.YEAR
                            AND m1.hcc_model_category1 = 7
                            AND m2.diag_code = m1.icd9cmscode) THEN 1 ELSE 0 END AS      DISEASE_COEF_HCC7,
           CASE WHEN EXISTS (SELECT m1.hcc_model_category1 FROM HCC_MODEL_DIAGNOSIS M1 , HCC_MODEL_DIAGNOSIS_MAPPING HM
                            ,mor222 m2 WHERE m1.map_id = hm.map_id_ref
                            AND m2.YEAR = hm.YEAR
                            AND o.cn = m2.cn
                            AND o.YEAR = hm.YEAR
                            AND m1.hcc_model_category1 = 8
                            AND m2.diag_code = m1.icd9cmscode) THEN 1 ELSE 0 END AS       DISEASE_COEF_HCC8                   
      FROM (SELECT T.cn,
                   T.BEN_LAST_NAME,
                   T.BEN_FIRST_NAME,
                   T.BEN_MI,
                   T.SSN,
                   TO_DATE(T.DOB, 'YYYYMMDD') AS DOB,
                   T.SEX,
                   TRUNC(MONTHS_BETWEEN(TO_DATE('01/01/' || T.YEAR, 'MM/DD/YYYY'),
                                        TO_DATE(T.DOB, 'YYYYMMDD')) / 12) AS AGE,
                   T.YEAR
              FROM mor111 T ) O Thanks in advance!
    Kind regards,
    Nik

    Ok, so I am going to be a little bit kinder then your first reply, but not much.
    From what can tell you are doing medical management and are trying to select by AGE/GENDER CELLS and this is common when trying to deal with RBRVS.
    This is by far some of the worst sql I have ever seen, sorry but it just is.
    So please report this either as a new post or as a reply and:
    1. At least post the table definitions and if you can some sample data.
    2. Get rid of almost all the case selectors.
    3. Describe the output you need.
    As it is this is unreadable.
    After that we can talk more.
    Edited by: FlyingGuy on Oct 11, 2011 5:13 PM

  • Need help in optimizing the query with joins and group by clause

    I am having problem in executing the query below.. it is taking lot of time. To simplify, I have added the two tables FILE_STATUS = stores the file load details and COMM table that is actual business commission table showing records successfully processed and which records were transmitted to other system. Records with status = T is trasnmitted to other system and traansactions with P is pending.
    CREATE TABLE FILE_STATUS
    (FILE_ID VARCHAR2(14),
    FILE_NAME VARCHAR2(20),
    CARR_CD VARCHAR2(5),
    TOT_REC NUMBER,
    TOT_SUCC NUMBER);
    CREATE TABLE COMM
    (SRC_FILE_ID VARCHAR2(14),
    REC_ID NUMBER,
    STATUS CHAR(1));
    INSERT INTO FILE_STATUS VALUES ('12345678', 'CM_LIBM.TXT', 'LIBM', 5, 4);
    INSERT INTO FILE_STATUS VALUES ('12345679', 'CM_HIPNT.TXT', 'HIPNT', 4, 0);
    INSERT INTO COMM VALUES ('12345678', 1, 'T');
    INSERT INTO COMM VALUES ('12345678', 3, 'T');
    INSERT INTO COMM VALUES ('12345678', 4, 'P');
    INSERT INTO COMM VALUES ('12345678', 5, 'P');
    COMMIT;Here is the query that I wrote to give me the details of the file that has been loaded into the system. It reads the file status and commission table to show file name, total records loaded, total records successfully loaded to the commission table and number of records that has been finally transmitted (status=T) to other systems.
    SELECT
        FS.CARR_CD
        ,FS.FILE_NAME
        ,FS.FILE_ID
        ,FS.TOT_REC
        ,FS.TOT_SUCC
        ,NVL(C.TOT_TRANS, 0) TOT_TRANS
    FROM FILE_STATUS FS
    LEFT JOIN
        SELECT SRC_FILE_ID, COUNT(*) TOT_TRANS
        FROM COMM
        WHERE STATUS = 'T'
        GROUP BY SRC_FILE_ID
    ) C ON C.SRC_FILE_ID = FS.FILE_ID
    WHERE FILE_ID = '12345678';In production this query has more joins and is taking lot of time to process.. the main culprit for me is the join on COMM table to get the count of number of transactions transmitted. Please can you give me tips to optimize this query to get results faster? Do I need to remove group and use partition or something else. Please help!

    I get 2 rows if I use my query with your new criteria. Did you commit the record if you are using a second connection to query? Did you remove the criteria for file_id?
    select carr_cd, file_name, file_id, tot_rec, tot_succ, tot_trans
      from (select fs.carr_cd,
                   fs.file_name,
                   fs.file_id,
                   fs.tot_rec,
                   fs.tot_succ,
                   count(case
                            when c.status = 'T' then
                             1
                            else
                             null
                          end) over(partition by c.src_file_id) tot_trans,
                   row_number() over(partition by c.src_file_id order by null) rn
              from file_status fs
              left join comm c
                on c.src_file_id = fs.file_id
             where carr_cd = 'LIBM')
    where rn = 1;
    CARR_CD FILE_NAME            FILE_ID           TOT_REC   TOT_SUCC  TOT_TRANS
    LIBM    CM_LIBM.TXT          12345678                5          4          2
    LIBM    CM_LIBM.TXT          12345677               10          0          0Using RANK can potentially produce multiple rows to be returned though your data may prevent this. ROW_NUMBER will always prevent duplicates. The ordering of the analytical function is irrelevant in your query if you use ROW_NUMBER. You can remove the outermost query and inspect the data returned by the inner query;
    select fs.carr_cd,
           fs.file_name,
           fs.file_id,
           fs.tot_rec,
           fs.tot_succ,
           count(case
                    when c.status = 'T' then
                     1
                    else
                     null
                  end) over(partition by c.src_file_id) tot_trans,
           row_number() over(partition by c.src_file_id order by null) rn
    from file_status fs
    left join comm c
    on c.src_file_id = fs.file_id
    where carr_cd = 'LIBM';
    CARR_CD FILE_NAME            FILE_ID           TOT_REC   TOT_SUCC  TOT_TRANS         RN
    LIBM    CM_LIBM.TXT          12345678                5          4          2          1
    LIBM    CM_LIBM.TXT          12345678                5          4          2          2
    LIBM    CM_LIBM.TXT          12345678                5          4          2          3
    LIBM    CM_LIBM.TXT          12345678                5          4          2          4
    LIBM    CM_LIBM.TXT          12345677               10          0          0          1

Maybe you are looking for

  • How to match the BI Inventory Management reports with MB5B?

    Hi All, In BI we have two reports which shows the Quantity, Value and count of the valuated GI and GR movements happened in the inventory at a material-plant level for a given day. Both the reports are built on the cube 0IC_C03(Material Stocks/Moveme

  • How can i open a slide in another file on clicking a button from another file

    Hello guys! This is my first post on captivate community. I've sucked into a problem. Is this possible somehow to open a slide in another file while clicking on a button that is in a different file. Any help would be appreciated. Thanks

  • All my music did not load to the iCloud Service

    I just purchased the Icloud service and tried to load all of my itunes music, I had it all organized in order and they did not load all of the music and left out almost 500 songs, I keep trying to do the last part no.3, and it keeps coming up with an

  • How do you turn off hibernation

    hi there just come across from windows all these years and as u can see in my previous post im having trouble with my mac, but one other question i must ask is that is it possible to stop the computer going into hibernation when i put the lid down on

  • If You're Wondering If You Can Switch To APE From FiOS Router

    I have spent the better part of two days scouring forums trying to find out if I can dump my D-Link DI-624 router I got when I subscribed to Verizon FiOS Internet in early 2005 and switch to the latest AirPort Extreme Base Station. The search for det