Need help on the below query or Pl-SQL

Hello Every one,
Please let me know if some one can help me out with the below scenario either in pl-sql or sql.
Source Data:
0000253800     0.25          0845A     0900A
0000253800     1          0900A     1000A
0000253800     1          1300P     1400P
0000253800     1          1500P     1600P
0000253800     1          1600P     1700P
Output needed:
0000253800     1.25          0845A     1000A
0000253800     1          1300P     1400P
0000253800     2          1500P     1700P
Thanks in Advance....
Edited by: user12564103 on Dec 11, 2011 5:54 PM

Hi,
Welcome to the forum!
Depending on your data and your requirements:
WITH     got_times     AS
     SELECT     column_1, column_2, column_3, column_4
     ,     TO_DATE ( substr (column_3, 1, 4)
               , 'HH24MI'
               )     AS time_3
     ,     TO_DATE ( SUBSTR (column_4, 1, 4)
               , 'HH24MI'
               )     AS time_4
     FROM     table_x
,     got_grp_id     AS
     SELECT     column_1, column_2, column_3, column_4
     ,     time_3, time_4
     ,     time_4 - SUM (time_4 - time_3) OVER ( PARTITION BY  column_1
                                    ORDER BY         time_3
                                  )     AS grp_id
     FROM     got_times
SELECT       column_1
,       SUM (column_2)     AS sum_2
,       MIN (column_3) KEEP (DENSE_RANK FIRST ORDER BY time_3)
                    AS min_3
,       MAX (column_4) KEEP (DENSE_RANK LAST  ORDER BY time_4)
                    AS max_4
FROM       got_grp_id
GROUP BY  column_1
,       grp_id
ORDER BY  column_1
,       grp_id
;Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, as well as the results you want from that data. Explain, with specific examples, how you get the results you want from that data.
Always say which version of Oracle you're using. The query above will work in Oracle 9.1 (and higher).
Since this is your first thread, I'll do this for you:
CREATE TABLE     table_x
(     column_1     NUMBER
,     column_2     NUMBER
,     column_3     VARCHAR2 (5)
,     column_4     VARCHAR2 (5)
INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, .25, '0845A', '0900A');
INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '0900A', '1000A');
INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '1300P', '1400P');
INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '1500P', '1600P');
INSERT INTO table_x (column_1, column_2, column_3, column_4) VALUES (253800, 1,   '1600P', '1700P');Column_1 identifes a day.
Column_2 is an amount that I need to total.
Column_3 and column_4 are starting and ending times. We can assume that they are all valid times (in 'HH24MI' format, plus a redundant 'A' or 'P') on the same day, column_3 is always less than column_4, and that the range of two rows for the same value of column_1 never overlap. Column_4 of one row may be equal to column_3 of another rows with the same column_1, but it will never be greater.
Each row of the output represent a contiguous group of rows (each ending exactly when the next one begins) with the same column_1, with the common column_1, the total of column_2, and the range of the group.
For example, the first two rows for a single group, because they have the same value for column_1, and one ends exactly when the other begins (at 9:00 AM). This group represents day 253800, from 8:45 AM to 10:00 AM. The totla of column_2 fro this group is .25 + 1 = 1.25.
The next row (from 1:00 PM to 2:00 PM) is a group all by itself, because there is a gap one either side of it separating it from its nearest neighbor on the same day."
Of course, I'm guessing at lots of things.
Edited by: Frank Kulash on Dec 11, 2011 9:44 PM
Changed TO_DATE calls.
Edited by: Frank Kulash on Dec 11, 2011 9:52 PM
Added sample question.

Similar Messages

  • Need help on the below query.

    Hi All,
    I've a query given below..
    SELECT W.WONUM,
         W.STATUS,
         WS.CHANGEDATE,
         EH.OLD_RATE
         FROM
         WORKORDER W,
         WOSTATUS WS,
         ESTIMATE_HEADER@GQMFOF EH
    WHERE WS.CHANGEDATE BETWEEN '01-Oct-2009' AND '1-Nov-2009'
    AND W.WONUM = WS.WONUM
    AND EH.OLD_RATE = 'N'
    AND WS.WOSTATUS = 'CLOSE';
    I would like to get All the data which status =closed in the month of Oct for Old rate,
    So for this i am writing the query above. But not getting the o/p.
    It is giving me that " Table/View doesn't exist.
    There 2 schemas MAXIMO,GQMMGR..
    DBlinks are GQMFOF,MAXFOFNC..
    Can anyone help me while writing the above query...
    Regards,
    gr.

    A question was asked in your other thread. But the problem was you dint care to give an answer.
    Dont open duplicate post.
    I need help on the below problem..

  • Need Help with the below query

    Hi All,
    I'm working on Oracle HRMS tables which have date tracking facility.
    I'm working on Oracle 10G.
    I have a table per_all_assignments_f(seeded) which contains the employee related information.
    It has normal hours and the assignment_id(primary key) in the table
    The data is something like
    assignment_id     
    123                   30                   01-Jan-2000               31-dec-2009
    123                    32                 01-Jan-2010               31-dec-2012
    123                  
    assignment_id
    Normal_hours
    Effective_start_Date
    Effective_end_Date
    123    
    30
    01-Jan-2000
    31-dec-2009
    123
    32
    01-Jan-2010
    31-dec-2012
    123
    40
    01-Jan-20103
    40                  01-jan-2013               31-dec-4712
    Now I'd like to pass the latest date(sysdate) to a function which should give me the
    last changed normal hours as on today. In this case 32.
    select normal_hours from per_all_assignments_f where
    assignment_id=123
    and trunc(latest_date) between effective_start_date and effective_end_date
    This will give me the latest normal hours of 40 but I want the last changed hours irrespective of how many ever be the changes.
    hope I'm clear in specifying my requirement.
    Appreciate your time
    Thanks,
    AJ

    877722 wrote:
    It has normal hours and the assignment_id(primary key) in the table
    How PK value is repeating in your sample data!
    877722 wrote:
    This will give me the latest normal hours of 40 but I want the last changed hours irrespective of how many ever be the changes.
    hope I'm clear in specifying my requirement.
    Nope. What is "changed hours"? Not able to break your source code!  a tough one, I say.
    By the way, follow the link shared by Karthick and will be easy to answer for anyone.
    Thanks!

  • I need help on the below problem..

    Hi All,
    I need help on the below problem..
    I've 2 Schemas called
         1. MAXIMO and DBLink is GQMFOF
         2. GQMMGR adn DBLink is MAXFOFNC
    Now i would likw to retrive the data from both the schemas,
    i.e some columns from WORKORDER table of maximo schema and some columns from ESTIMATE_HEADER table
    of GQMMGR schema..
    I'm trying to get the data using DB links, but it is giving TABLE/VIEW doesn't exist.
    Please help me on this.
    Regards,
    gr.

    Does your user has the SELECT privelage granted for accessing those tables?

  • Need help in the below command excution

    Hi Champs,
    Can any one help with the below command, It is not working.
    Get-CsUser | Where-Object {$_.dialplan -eq "USDAL"} | Grant-CsLocationPolicy -PolicyName "Dallas Location Policy"
    Regards
    Vijendhar

    You could try something like: 
    $userlist = Get-CsUser -ResultSize Unlimited
    foreach ($user in $userlist)
    if ($user.dialplan -eq $Null)
    $pool = (Get-csdialplan | Where-Object {$_.Identity -like ("*" + $user.RegistrarPool)})
    if ($pool.length -ge "1") {write-host ("Pool simple name: " + $pool.simplename + ", Identity: " + $pool.identity)}
    if (($pool.simplename -eq "USDal") -or ($pool.identity -eq "USDal"))
    Write-host "Please Grant location policy to: $user.Displayname"
    # Get-csuser $user.identity | Grant-CsLocationPolicy -PolicyName "Dallas Location Policy"
    $pool = $Null
    Use at your own risk as I haven't had a chance to test, I have commented out the grant so you can test prior to changes.
    Please mark posts as answers/helpful if it answers your question.
    Blog
    Lync Validator - Used to assist in the validation and documentation of Lync Server 2013.

  • Need help in the following query

    Hi ,
    I have the following query to pull out data for a particular timeperiod( campaign)
    select
    da.acct_nr,smas.mrkt_id,smas.fld_sls_cmpgn_perd_id,smas.acct_key,smas.upln_acct_key,smas.awrd_sls_amt,smas.fld_net_sls_amt
    ,smas.stf_ind,da1.acct_nr,
    smas.fld_sls_cmpgn_perd_id,smas.acct_key,smas.upln_acct_key,smas.awrd_sls_amt,smas.fld_net_sls_amt
    ,smas.stf_ind,da1.acct_nr,prev.*
    From cdw.sum_mrkt_acct_sls smas
    join codi.dim_acct da
    on (smas.mrkt_id = da.mrkt_id and smas.acct_key = da.acct_key)
    join codi.dim_acct da1
    on (smas.mrkt_id = da1.mrkt_id and smas.UPLN_acct_key = da1.ACCT_KEY)
    where smas.acct_key in
    select dwnln_acct_key from codi.dim_ldrshp_genlgy
    where mrkt_id = 66 and fld_sls_cmpgn_perd_id = 20100304
    and root_upln_acct_key = (select acct_key from codi.dim_acct where acct_nr = '0032622' and mrkt_id = 66)
    and
    smas.mrkt_id = 66
    and smas.fld_sls_cmpgn_perd_id = 20100304
    and smas.sls_org_key <> -100
    order by 1
    So this query will pull out data for campaign 20100304
    No i want to modify the query to pull out data for 3 such campaigns.
    for a smas.acct_key
    so data will
    smas.acct_key all the data for 1st campaign , all the data for 2nd campaign. all the data for 3rd campaign
    Could you please help in modifying this query.
    Thanks

    How about this ??
    select da.acct_nr,
           smas.mrkt_id,
           smas.fld_sls_cmpgn_perd_id,
           smas.acct_key,
           smas.upln_acct_key,
           smas.awrd_sls_amt,
           smas.fld_net_sls_amt,
           smas.stf_ind,
           da1.acct_nr,
           smas.fld_sls_cmpgn_perd_id,
           smas.acct_key,
           smas.upln_acct_key,
           smas.awrd_sls_amt,
           smas.fld_net_sls_amt,
           smas.stf_ind,
           da1.acct_nr,
           prev.*
      From cdw.sum_mrkt_acct_sls smas
      join codi.dim_acct da on (smas.mrkt_id = da.mrkt_id and
                               smas.acct_key = da.acct_key)
      join codi.dim_acct da1 on (smas.mrkt_id = da1.mrkt_id and
                                smas.UPLN_acct_key = da1.ACCT_KEY)
    where smas.acct_key in (select dwnln_acct_key
                               from codi.dim_ldrshp_genlgy
                              where mrkt_id = 66
                                and fld_sls_cmpgn_perd_id in( 20100304,20100305,20100306)
                                and root_upln_acct_key =
                                    (select acct_key
                                       from codi.dim_acct
                                      where acct_nr = '0032622'
                                        and mrkt_id = 66))
       and smas.mrkt_id = 66
       and smas.fld_sls_cmpgn_perd_id in( 20100304,20100305,20100306)
       and smas.sls_org_key - 100
    order by 1

  • Need to tune the below query.

    Query below:
    I have generated the explain plan for the same and its cost is overall 2089...
    But Strange once I have removed the "ORDER SIBLINGS BY RETAILER_NM" from below then its cost is coming overall 40.
    Can U suggest me what is the best solution.
    SELECT path as Retailer_id, logical_physical_flg, parent_retailer_id, upper(retailer_nm), max_level
    FROM (SELECT A.RETAILER_ID,LOGICAL_PHYSICAL_FLG, NULL AS PARENT_RETAILER_ID, B.RETAILER_NM, a.retailer_id path,
    (LEVEL+2) AS MAX_LEVEL FROM
    RETAILER B, USER_RETAILER_MAP A WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND
    B.RETAILER_ID=A.RETAILER_ID AND B.STATUS='ACTIVE' AND
    A.RETAILER_ID NOT IN (SELECT DISTINCT RETAILER_ID FROM
    RETAILER_HIERARCHY START WITH PARENT_RETAILER_ID IN (SELECT RETAILER_ID FROM USER_RETAILER_MAP A
    WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND MANAGED_BY='Y') CONNECT BY PRIOR RETAILER_ID=PARENT_RETAILER_ID)
    AND MANAGED_BY='Y'
    UNION
    SELECT a.RETAILER_ID, LOGICAL_PHYSICAL_FLG, replace(sys_connect_by_path(decode(level, 1, a.parent_retailer_id), '~'), '~') parent_retailer_id, RETAILER_NM, LPAD(' ', 2*LEVEL-1)||SYS_CONNECT_BY_PATH(B.RETAILER_ID, '/') AS path, LEVEL+3 AS MAX_LEVEL
    FROM RETAILER B, RETAILER_HIERARCHY A
    WHERE B.RETAILER_ID=A.RETAILER_ID AND UPPER(B.STATUS)='ACTIVE' AND EXISTS
    (SELECT RETAILER_ID FROM USER_RETAILER_MAP C WHERE USER_ID = 'ALEX.CAYLESS@GMACIO' AND
    B.RETAILER_ID = C.RETAILER_ID AND MANAGED_BY= 'Y')
    START WITH PARENT_RETAILER_ID IN (SELECT A.RETAILER_ID FROM
    RETAILER B, USER_RETAILER_MAP A WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND B.RETAILER_ID=A.RETAILER_ID
    AND UPPER(B.STATUS)='ACTIVE' AND A.RETAILER_ID NOT IN (SELECT DISTINCT RETAILER_ID FROM
    RETAILER_HIERARCHY START WITH PARENT_RETAILER_ID IN (SELECT RETAILER_ID FROM USER_RETAILER_MAP A
    WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND MANAGED_BY='Y') CONNECT BY PRIOR RETAILER_ID=PARENT_RETAILER_ID)
    AND MANAGED_BY='Y') CONNECT BY PRIOR A.RETAILER_ID=PARENT_RETAILER_ID )
    START WITH PARENT_RETAILER_ID IS NULL CONNECT BY PRIOR RETAILER_ID = PARENT_RETAILER_ID
    ORDER SIBLINGS BY RETAILER_NM
    Explain Plan:
    ==========================
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 1352 | 5385K| 2089 |
    |* 1 | CONNECT BY WITH FILTERING | | | | |
    |* 2 | FILTER | | | | |
    | 3 | COUNT | | | | |
    | 4 | VIEW | | 1352 | 5385K| 40 |
    | 5 | SORT UNIQUE | | 1352 | 84128 | 40 |
    | 6 | UNION-ALL | | | | |
    |* 7 | HASH JOIN ANTI | | 16 | 1296 | 12 |
    |* 8 | HASH JOIN | | 19 | 1406 | 9 |
    | 9 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 10 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 2409 | | 1 |
    |* 11 | TABLE ACCESS FULL | RETAILER | 1594 | 70136 | 6 |
    | 12 | VIEW | VW_NSO_1 | 3 | 21 | 2 |
    |* 13 | CONNECT BY WITH FILTERING | | | | |
    | 14 | NESTED LOOPS | | | | |
    |* 15 | HASH JOIN | | 58 | 2262 | 5 |
    | 16 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 17 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 18 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 19 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 20 | NESTED LOOPS | | | | |
    | 21 | BUFFER SORT | | 3 | 54 | |
    | 22 | CONNECT BY PUMP | | | | |
    |* 23 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |* 24 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 25 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |* 26 | FILTER | | | | |
    |* 27 | CONNECT BY WITH FILTERING | | | | |
    |* 28 | FILTER | | | | |
    | 29 | COUNT | | | | |
    |* 30 | HASH JOIN | | 1336 | 82832 | 9 |
    | 31 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
    | 32 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
    | 33 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
    | 34 | NESTED LOOPS | | 1 | 47 | 3 |
    |* 35 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 36 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |* 37 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
    |* 38 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
    |* 39 | VIEW | VW_NSO_3 | 3 | 21 | |
    |* 40 | CONNECT BY WITH FILTERING | | | | |
    | 41 | NESTED LOOPS | | | | |
    |* 42 | HASH JOIN | | 58 | 2262 | 5 |
    | 43 | TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 44 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 45 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 46 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 47 | NESTED LOOPS | | | | |
    | 48 | BUFFER SORT | | 3 | 54 | |
    | 49 | CONNECT BY PUMP | | | | |
    |* 50 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |* 51 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 52 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    | 53 | HASH JOIN | | | | |
    | 54 | CONNECT BY PUMP | | | | |
    | 55 | COUNT | | | | |
    |* 56 | HASH JOIN | | 1336 | 82832 | 9 |
    | 57 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
    | 58 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
    | 59 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
    | 60 | NESTED LOOPS | | 1 | 47 | 3 |
    |* 61 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 62 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |* 63 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
    |* 64 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
    |* 65 | VIEW | VW_NSO_3 | 3 | 21 | |
    |* 66 | CONNECT BY WITH FILTERING | | | | |
    | 67 | NESTED LOOPS | | | | |
    |* 68 | HASH JOIN | | 58 | 2262 | 5 |
    | 69 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 70 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 71 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 72 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 73 | NESTED LOOPS | | | | |
    | 74 | BUFFER SORT | | 3 | 54 | |
    | 75 | CONNECT BY PUMP | | | | |
    |* 76 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |* 77 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 78 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |* 79 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 80 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    | 81 | HASH JOIN | | | | |
    | 82 | CONNECT BY PUMP | | | | |
    | 83 | COUNT | | | | |
    | 84 | VIEW | | 1352 | 5385K| 40 |
    | 85 | SORT UNIQUE | | 1352 | 84128 | 40 |
    | 86 | UNION-ALL | | | | |
    |* 87 | HASH JOIN ANTI | | 16 | 1296 | 12 |
    |* 88 | HASH JOIN | | 19 | 1406 | 9 |
    | 89 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 90 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 2409 | | 1 |
    |* 91 | TABLE ACCESS FULL | RETAILER | 1594 | 70136 | 6 |
    | 92 | VIEW | VW_NSO_1 | 3 | 21 | 2 |
    |* 93 | CONNECT BY WITH FILTERING | | | | |
    | 94 | NESTED LOOPS | | | | |
    |* 95 | HASH JOIN | | 58 | 2262 | 5 |
    | 96 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 97 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 98 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 99 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 100 | NESTED LOOPS | | | | |
    | 101 | BUFFER SORT | | 3 | 54 | |
    | 102 | CONNECT BY PUMP | | | | |
    |*103 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |*104 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*105 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |*106 | FILTER | | | | |
    |*107 | CONNECT BY WITH FILTERING | | | | |
    |*108 | FILTER | | | | |
    | 109 | COUNT | | | | |
    |*110 | HASH JOIN | | 1336 | 82832 | 9 |
    | 111 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
    | 112 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
    | 113 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
    | 114 | NESTED LOOPS | | 1 | 47 | 3 |
    |*115 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*116 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |*117 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
    |*118 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
    |*119 | VIEW | VW_NSO_3 | 3 | 21 | |
    |*120 | CONNECT BY WITH FILTERING | | | | |
    | 121 | NESTED LOOPS | | | | |
    |*122 | HASH JOIN | | 58 | 2262 | 5 |
    | 123 | TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP | 19 | 570 | 2 |
    |*124 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 125 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 126 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 127 | NESTED LOOPS | | | | |
    | 128 | BUFFER SORT | | 3 | 54 | |
    | 129 | CONNECT BY PUMP | | | | |
    |*130 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |*131 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*132 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    | 133 | HASH JOIN | | | | |
    | 134 | CONNECT BY PUMP | | | | |
    | 135 | COUNT | | | | |
    |*136 | HASH JOIN | | 1336 | 82832 | 9 |
    | 137 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
    | 138 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
    | 139 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
    | 140 | NESTED LOOPS | | 1 | 47 | 3 |
    |*141 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*142 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |*143 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
    |*144 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
    |*145 | VIEW | VW_NSO_3 | 3 | 21 | |
    |*146 | CONNECT BY WITH FILTERING | | | | |
    | 147 | NESTED LOOPS | | | | |
    |*148 | HASH JOIN | | 58 | 2262 | 5 |
    | 149 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |*150 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 151 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 152 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 153 | NESTED LOOPS | | | | |
    | 154 | BUFFER SORT | | 3 | 54 | |
    | 155 | CONNECT BY PUMP | | | | |
    |*156 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |*157 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*158 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |*159 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*160 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    Predicate Information (identified by operation id):
    1 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)
    2 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)
    7 - access("A"."RETAILER_ID"="VW_NSO_1"."$nso_col_1")
    8 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    10 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    11 - filter("B"."STATUS"='ACTIVE')
    13 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    15 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    17 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    23 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    24 - filter("A"."MANAGED_BY"='Y')
    25 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    26 - filter(UPPER("SYS_ALIAS_1"."STATUS")='ACTIVE' AND EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILE
    R_MAP" "C" WHERE "C"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "C"."RETAILER_ID"=:B1 AND "C"
    ."MANAGED_BY"='Y'))
    27 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
    SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
    "SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
    ."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
    AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
    "='Y'))
    28 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
    SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
    "SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
    ."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
    AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
    "='Y'))
    30 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
    35 - filter("A"."MANAGED_BY"='Y')
    36 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    37 - filter(UPPER("B"."STATUS")='ACTIVE')
    38 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    39 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
    40 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    42 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    44 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    50 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    51 - filter("A"."MANAGED_BY"='Y')
    52 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    56 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
    61 - filter("A"."MANAGED_BY"='Y')
    62 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    63 - filter(UPPER("B"."STATUS")='ACTIVE')
    64 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    65 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
    66 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    68 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    70 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    76 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    77 - filter("A"."MANAGED_BY"='Y')
    78 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    79 - filter("C"."MANAGED_BY"='Y')
    80 - access("C"."RETAILER_ID"=:B1 AND "C"."USER_ID"='ALEX.CAYLESS@GMACIO')
    87 - access("A"."RETAILER_ID"="VW_NSO_1"."$nso_col_1")
    88 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    90 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    91 - filter("B"."STATUS"='ACTIVE')
    93 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    95 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    97 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    103 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    104 - filter("A"."MANAGED_BY"='Y')
    105 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    106 - filter(UPPER("SYS_ALIAS_1"."STATUS")='ACTIVE' AND EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILE
    R_MAP" "C" WHERE "C"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "C"."RETAILER_ID"=:B1 AND "C"
    ."MANAGED_BY"='Y'))
    107 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
    SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
    "SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
    ."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
    AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
    "='Y'))
    108 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
    SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
    "SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
    ."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
    AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
    "='Y'))
    110 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
    115 - filter("A"."MANAGED_BY"='Y')
    116 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    117 - filter(UPPER("B"."STATUS")='ACTIVE')
    118 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    119 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
    120 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    122 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    124 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    130 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    131 - filter("A"."MANAGED_BY"='Y')
    132 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    136 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
    141 - filter("A"."MANAGED_BY"='Y')
    142 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    143 - filter(UPPER("B"."STATUS")='ACTIVE')
    144 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    145 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
    146 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    148 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    150 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    156 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    157 - filter("A"."MANAGED_BY"='Y')
    158 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    159 - filter("C"."MANAGED_BY"='Y')
    160 - access("C"."RETAILER_ID"=:B1 AND "C"."USER_ID"='ALEX.CAYLESS@GMACIO')
    Edited by: user13345267 on Jul 19, 2010 1:56 AM

    Please find formatted sql.
    SELECT path AS retailer_id,
           logical_physical_flg,
           parent_retailer_id,
           Upper(retailer_nm),
           max_level
    FROM   (SELECT a.retailer_id,
                   logical_physical_flg,
                   NULL          AS parent_retailer_id,
                   b.retailer_nm,
                   a.retailer_id path,
                   ( LEVEL + 2 ) AS max_level
            FROM   retailer b,
                   user_retailer_map a
            WHERE  user_id = 'ALEX.CAYLESS@GMACIO'
                   AND b.retailer_id = a.retailer_id
                   AND b.status = 'ACTIVE'
                   AND a.retailer_id NOT IN (SELECT DISTINCT retailer_id
                                             FROM   retailer_hierarchy
                                             START WITH parent_retailer_id IN (
                                                        SELECT
                                                        retailer_id
                                                                               FROM
                                                        user_retailer_map a
                                                                               WHERE
                                             user_id = 'ALEX.CAYLESS@GMACIO'
                                             AND managed_by = 'Y')
                                             CONNECT BY PRIOR
                                             retailer_id = parent_retailer_id)
                   AND managed_by = 'Y'
            UNION
            SELECT a.retailer_id,
                   logical_physical_flg,
                   Replace(Sys_connect_by_path(
                           Decode(LEVEL, 1, a.parent_retailer_id), '~')
                   '~')
                                                             parent_retailer_id,
                   retailer_nm,
                   Lpad(' ', 2 * LEVEL - 1)
                   ||Sys_connect_by_path(b.retailer_id, '/') AS path,
                   LEVEL + 3                                 AS max_level
            FROM   retailer b,
                   retailer_hierarchy a
            WHERE  b.retailer_id = a.retailer_id
                   AND Upper(b.status) = 'ACTIVE'
                   AND EXISTS (SELECT retailer_id
                               FROM   user_retailer_map c
                               WHERE  user_id = 'ALEX.CAYLESS@GMACIO'
                                      AND b.retailer_id = c.retailer_id
                                      AND managed_by = 'Y')
            START WITH parent_retailer_id IN (SELECT a.retailer_id
                                              FROM   retailer b,
                                                     user_retailer_map a
                                              WHERE  user_id = 'ALEX.CAYLESS@GMACIO'
                                                     AND
                                             b.retailer_id = a.retailer_id
                                                     AND Upper(b.status) = 'ACTIVE'
                                                     AND a.retailer_id NOT IN
                                                         (SELECT DISTINCT
                                                         retailer_id
                                                          FROM   retailer_hierarchy
                                             START WITH parent_retailer_id IN
                                                        SELECT
                                                        retailer_id
                                                        FROM
                                                        user_retailer_map a
                                                        WHERE
                                             user_id = 'ALEX.CAYLESS@GMACIO'
                                             AND managed_by = 'Y')
                                             CONNECT BY PRIOR
                                             retailer_id = parent_retailer_id)
                                                     AND managed_by = 'Y')
            CONNECT BY PRIOR a.retailer_id = parent_retailer_id)
    START WITH parent_retailer_id IS NULL
    CONNECT BY PRIOR retailer_id = parent_retailer_id
    ORDER SIBLINGS BY RETAILER_NM
    Execution Plan
    ====================================
    PLAN_TABLE_OUTPUT                                                                                                                  
    | Id  | Operation                                 |  Name                     | Rows  | Bytes | Cost  |                            
    |   0 | SELECT STATEMENT                          |                           |  1352 |  5385K|  2089 |                            
    |*  1 |  CONNECT BY WITH FILTERING                |                           |       |       |       |                            
    |*  2 |   FILTER                                  |                           |       |       |       |                            
    |   3 |    COUNT                                  |                           |       |       |       |                            
    |   4 |     VIEW                                  |                           |  1352 |  5385K|    40 |                            
    |   5 |      SORT UNIQUE                          |                           |  1352 | 84128 |    40 |                            
    |   6 |       UNION-ALL                           |                           |       |       |       |                            
    |*  7 |        HASH JOIN ANTI                     |                           |    16 |  1296 |    12 |                            
    |*  8 |         HASH JOIN                         |                           |    19 |  1406 |     9 |                            
    |   9 |          TABLE ACCESS BY INDEX ROWID      | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 10 |           INDEX RANGE SCAN                | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |* 11 |          TABLE ACCESS FULL                | RETAILER                  |    32 |  1408 |     6 |                            
    |  12 |         VIEW                              | VW_NSO_1                  |     3 |    21 |     2 |                            
    |* 13 |          CONNECT BY WITH FILTERING        |                           |       |       |       |                            
    |  14 |           NESTED LOOPS                    |                           |       |       |       |                            
    |* 15 |            HASH JOIN                      |                           |    58 |  2262 |     5 |                            
    |  16 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 17 |              INDEX RANGE SCAN             | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |  18 |             INDEX FAST FULL SCAN          | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    |  19 |            TABLE ACCESS BY USER ROWID     | RETAILER_HIERARCHY        |       |       |       |                            
    |  20 |           NESTED LOOPS                    |                           |       |       |       |                            
    |  21 |            BUFFER SORT                    |                           |     3 |    54 |       |                            
    |  22 |             CONNECT BY PUMP               |                           |       |       |       |                            
    |* 23 |            INDEX FAST FULL SCAN           | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |* 24 |           TABLE ACCESS BY INDEX ROWID     | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 25 |            INDEX UNIQUE SCAN              | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |* 26 |        FILTER                             |                           |       |       |       |                            
    |* 27 |         CONNECT BY WITH FILTERING         |                           |       |       |       |                            
    |* 28 |          FILTER                           |                           |       |       |       |                            
    |  29 |           COUNT                           |                           |       |       |       |                            
    |* 30 |            HASH JOIN                      |                           |  1336 | 82832 |     9 |                            
    |  31 |             INDEX FAST FULL SCAN          | XPKRETAILER_HIERARCHY     |  1336 | 24048 |     2 |                            
    |  32 |             TABLE ACCESS FULL             | RETAILER                  |  3188 |   136K|     6 |                            
    |  33 |           NESTED LOOPS ANTI               |                           |     1 |    54 |     5 |                            
    |  34 |            NESTED LOOPS                   |                           |     1 |    47 |     3 |                            
    |* 35 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 36 |              INDEX UNIQUE SCAN            | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |* 37 |             TABLE ACCESS BY INDEX ROWID   | RETAILER                  |     1 |    17 |     1 |                            
    |* 38 |              INDEX UNIQUE SCAN            | XPKRETAILER               |   100 |       |       |                            
    |* 39 |            VIEW                           | VW_NSO_3                  |     3 |    21 |       |                            
    |* 40 |             CONNECT BY WITH FILTERING     |                           |       |       |       |                            
    |  41 |              NESTED LOOPS                 |                           |       |       |       |                            
    |* 42 |               HASH JOIN                   |                           |    58 |  2262 |     5 |                            
    |  43 |                TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 44 |                 INDEX RANGE SCAN          | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |  45 |                INDEX FAST FULL SCAN       | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    |  46 |               TABLE ACCESS BY USER ROWID  | RETAILER_HIERARCHY        |       |       |       |                            
    |  47 |              NESTED LOOPS                 |                           |       |       |       |                            
    |  48 |               BUFFER SORT                 |                           |     3 |    54 |       |                            
    |  49 |                CONNECT BY PUMP            |                           |       |       |       |                            
    |* 50 |               INDEX FAST FULL SCAN        | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |* 51 |              TABLE ACCESS BY INDEX ROWID  | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 52 |               INDEX UNIQUE SCAN           | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |  53 |          HASH JOIN                        |                           |       |       |       |                            
    |  54 |           CONNECT BY PUMP                 |                           |       |       |       |                            
    |  55 |           COUNT                           |                           |       |       |       |                            
    |* 56 |            HASH JOIN                      |                           |  1336 | 82832 |     9 |                            
    |  57 |             INDEX FAST FULL SCAN          | XPKRETAILER_HIERARCHY     |  1336 | 24048 |     2 |                            
    |  58 |             TABLE ACCESS FULL             | RETAILER                  |  3188 |   136K|     6 |                            
    |  59 |          NESTED LOOPS ANTI                |                           |     1 |    54 |     5 |                            
    |  60 |           NESTED LOOPS                    |                           |     1 |    47 |     3 |                            
    |* 61 |            TABLE ACCESS BY INDEX ROWID    | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 62 |             INDEX UNIQUE SCAN             | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |* 63 |            TABLE ACCESS BY INDEX ROWID    | RETAILER                  |     1 |    17 |     1 |                            
    |* 64 |             INDEX UNIQUE SCAN             | XPKRETAILER               |   100 |       |       |                            
    |* 65 |           VIEW                            | VW_NSO_3                  |     3 |    21 |       |                            
    |* 66 |            CONNECT BY WITH FILTERING      |                           |       |       |       |                            
    |  67 |             NESTED LOOPS                  |                           |       |       |       |                            
    |* 68 |              HASH JOIN                    |                           |    58 |  2262 |     5 |                            
    |  69 |               TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 70 |                INDEX RANGE SCAN           | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |  71 |               INDEX FAST FULL SCAN        | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    |  72 |              TABLE ACCESS BY USER ROWID   | RETAILER_HIERARCHY        |       |       |       |                            
    |  73 |             NESTED LOOPS                  |                           |       |       |       |                            
    |  74 |              BUFFER SORT                  |                           |     3 |    54 |       |                            
    |  75 |               CONNECT BY PUMP             |                           |       |       |       |                            
    |* 76 |              INDEX FAST FULL SCAN         | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |* 77 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 78 |              INDEX UNIQUE SCAN            | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |* 79 |         TABLE ACCESS BY INDEX ROWID       | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 80 |          INDEX UNIQUE SCAN                | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |  81 |   HASH JOIN                               |                           |       |       |       |                            
    |  82 |    CONNECT BY PUMP                        |                           |       |       |       |                            
    |  83 |    COUNT                                  |                           |       |       |       |                            
    |  84 |     VIEW                                  |                           |  1352 |  5385K|    40 |                            
    |  85 |      SORT UNIQUE                          |                           |  1352 | 84128 |    40 |                            
    |  86 |       UNION-ALL                           |                           |       |       |       |                            
    |* 87 |        HASH JOIN ANTI                     |                           |    16 |  1296 |    12 |                            
    |* 88 |         HASH JOIN                         |                           |    19 |  1406 |     9 |                            
    |  89 |          TABLE ACCESS BY INDEX ROWID      | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 90 |           INDEX RANGE SCAN                | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |* 91 |          TABLE ACCESS FULL                | RETAILER                  |    32 |  1408 |     6 |                            
    |  92 |         VIEW                              | VW_NSO_1                  |     3 |    21 |     2 |                            
    |* 93 |          CONNECT BY WITH FILTERING        |                           |       |       |       |                            
    |  94 |           NESTED LOOPS                    |                           |       |       |       |                            
    |* 95 |            HASH JOIN                      |                           |    58 |  2262 |     5 |                            
    |  96 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 97 |              INDEX RANGE SCAN             | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |  98 |             INDEX FAST FULL SCAN          | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    |  99 |            TABLE ACCESS BY USER ROWID     | RETAILER_HIERARCHY        |       |       |       |                            
    | 100 |           NESTED LOOPS                    |                           |       |       |       |                            
    | 101 |            BUFFER SORT                    |                           |     3 |    54 |       |                            
    | 102 |             CONNECT BY PUMP               |                           |       |       |       |                            
    |*103 |            INDEX FAST FULL SCAN           | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |*104 |           TABLE ACCESS BY INDEX ROWID     | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*105 |            INDEX UNIQUE SCAN              | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |*106 |        FILTER                             |                           |       |       |       |                            
    |*107 |         CONNECT BY WITH FILTERING         |                           |       |       |       |                            
    |*108 |          FILTER                           |                           |       |       |       |                            
    | 109 |           COUNT                           |                           |       |       |       |                            
    |*110 |            HASH JOIN                      |                           |  1336 | 82832 |     9 |                            
    | 111 |             INDEX FAST FULL SCAN          | XPKRETAILER_HIERARCHY     |  1336 | 24048 |     2 |                            
    | 112 |             TABLE ACCESS FULL             | RETAILER                  |  3188 |   136K|     6 |                            
    | 113 |           NESTED LOOPS ANTI               |                           |     1 |    54 |     5 |                            
    | 114 |            NESTED LOOPS                   |                           |     1 |    47 |     3 |                            
    |*115 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*116 |              INDEX UNIQUE SCAN            | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |*117 |             TABLE ACCESS BY INDEX ROWID   | RETAILER                  |     1 |    17 |     1 |                            
    |*118 |              INDEX UNIQUE SCAN            | XPKRETAILER               |   100 |       |       |                            
    |*119 |            VIEW                           | VW_NSO_3                  |     3 |    21 |       |                            
    |*120 |             CONNECT BY WITH FILTERING     |                           |       |       |       |                            
    | 121 |              NESTED LOOPS                 |                           |       |       |       |                            
    |*122 |               HASH JOIN                   |                           |    58 |  2262 |     5 |                            
    | 123 |                TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |*124 |                 INDEX RANGE SCAN          | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    | 125 |                INDEX FAST FULL SCAN       | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    | 126 |               TABLE ACCESS BY USER ROWID  | RETAILER_HIERARCHY        |       |       |       |                            
    | 127 |              NESTED LOOPS                 |                           |       |       |       |                            
    | 128 |               BUFFER SORT                 |                           |     3 |    54 |       |                            
    | 129 |                CONNECT BY PUMP            |                           |       |       |       |                            
    |*130 |               INDEX FAST FULL SCAN        | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |*131 |              TABLE ACCESS BY INDEX ROWID  | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*132 |               INDEX UNIQUE SCAN           | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    | 133 |          HASH JOIN                        |                           |       |       |       |                            
    | 134 |           CONNECT BY PUMP                 |                           |       |       |       |                            
    | 135 |           COUNT                           |                           |       |       |       |                            
    |*136 |            HASH JOIN                      |                           |  1336 | 82832 |     9 |                            
    | 137 |             INDEX FAST FULL SCAN          | XPKRETAILER_HIERARCHY     |  1336 | 24048 |     2 |                            
    | 138 |             TABLE ACCESS FULL             | RETAILER                  |  3188 |   136K|     6 |                            
    | 139 |          NESTED LOOPS ANTI                |                           |     1 |    54 |     5 |                            
    | 140 |           NESTED LOOPS                    |                           |     1 |    47 |     3 |                            
    |*141 |            TABLE ACCESS BY INDEX ROWID    | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*142 |             INDEX UNIQUE SCAN             | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |*143 |            TABLE ACCESS BY INDEX ROWID    | RETAILER                  |     1 |    17 |     1 |                            
    |*144 |             INDEX UNIQUE SCAN             | XPKRETAILER               |   100 |       |       |                            
    |*145 |           VIEW                            | VW_NSO_3                  |     3 |    21 |       |                            
    |*146 |            CONNECT BY WITH FILTERING      |                           |       |       |       |                            
    | 147 |             NESTED LOOPS                  |                           |       |       |       |                            
    |*148 |              HASH JOIN                    |                           |    58 |  2262 |     5 |                            
    | 149 |               TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |*150 |                INDEX RANGE SCAN           | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    | 151 |               INDEX FAST FULL SCAN        | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    | 152 |              TABLE ACCESS BY USER ROWID   | RETAILER_HIERARCHY        |       |       |       |                            
    | 153 |             NESTED LOOPS                  |                           |       |       |       |                            
    | 154 |              BUFFER SORT                  |                           |     3 |    54 |       |                            
    | 155 |               CONNECT BY PUMP             |                           |       |       |       |                            
    |*156 |              INDEX FAST FULL SCAN         | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |*157 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*158 |              INDEX UNIQUE SCAN            | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |*159 |         TABLE ACCESS BY INDEX ROWID       | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*160 |          INDEX UNIQUE SCAN                | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    Predicate Information (identified by operation id):                                                                                
       1 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)                                                                  
       2 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)                                                                  
       7 - access("A"."RETAILER_ID"="VW_NSO_1"."$nso_col_1")                                                                           
       8 - access("B"."RETAILER_ID"="A"."RETAILER_ID")                                                                                 
      10 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')                                                        
      11 - filter("B"."STATUS"='ACTIVE')                                                                                               
      13 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES                               
                  S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))                                                       
      15 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")                                                         
      17 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')                                                        
      23 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)                                                                             
      24 - filter("A"."MANAGED_BY"='Y')                                                                                                
      25 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')                                                       
      26 - filter(UPPER("SYS_ALIAS_1"."STATUS")='ACTIVE' AND  EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILE                               
                  R_MAP" "C" WHERE "C"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "C"."RETAILER_ID"=:B1 AND "C"                               
                  ."MANAGED_BY"='Y'))                                                                                                  
      27 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "                               
                  SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE                                
                  "SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"                               
                  ."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

  • Need help with the following query

    I have the following data
    INVOICE_ID PAID_AMT PYMNT_GROSS_AMT DISCOUNT
    10151 1375 1375 55
    10151DC -44.81 -44.81 0
    20017 25 25 7
    Ok the data I want to grab the discount field is paid_amt = pymnt_gross_amt and discount <> 0. If however there is another invoice_id out there (same invoice ID except with a DC appended to it like 10151DC) then you want to select the differece between the discount field without the DC and the Invoice ID with the DC the paid_amt field.
    So the results would be.
    Invoice_ID Discount
    10151 10.19
    20017 7
    Thanks for all your help!

    Why scan same table twice when it can be achived using single scan :
    Hope this helps :
    with inv_data as
    (select '10151' invoice_id,
    1375 paid_amt,
              1375 pymnt_gross_amt,
              55 discount from dual
    union all
    select '10151DC' invoice_id,
    -44.81 paid_amt,
              -44.81 pymnt_gross_amt,
              0 discount from dual
    union all
    select '20017' invoice_id,
    25 paid_amt,
              25 pymnt_gross_amt,
              7 discount from dual)
    select replace(invoice_id,'DC') invoice_id,
    sum(case when invoice_id like '%DC' then pymnt_gross_amt
         else discount end) discount
    from inv_data
    group by replace(invoice_id,'DC')
    INVOICE DISCOUNT
    10151 10.19
    20017 7
    2 rows selected.

  • Help in the below query

    Hi ,
    I have the following string
    select '1, ,3, , , abc, ,dce,234, , , abc 1 ,1 ,4 ' from dual
    and i have translations for
    abc,dce and abc 1 respecitvely as
    X ,Y and Z
    which i strore in a table as
    1 abc X
    2 dce Y
    3 abc 1 Z
    now i want to replace these tranlations in my original string such that my spaces etc are intact ( note that i cannot use the replace function directly)
    MY final string should look like
    1, ,3, , , X, ,Y,234, , , Z ,1 ,4
    any pointers how i can achieve it.
    Thanks

    Prazy wrote:
    Aketi Jyuuzou wrote:
    I like recursive with clause B-)Yes but recursive with clause is being supported only from 11gR2 but OP is using *10gR2* B-)Hehe I was to start create SQL seeing OP's first Post only :-)
    And I prefer recursive with clause than model clause B-)
    And my prev SQL is wrong.
    with t as(
    select '1, ,3, , , abc, ,dce,234, , , abc 1 ,1 ,4 '
    as str from dual),
    repstr(ID,befo,aft) as(
    select 1,'abc','X' from dual union
    select 2,'dce','Y' from dual union
    select 3,'abc 1','Z' from dual),
    rec(str,LV) as(
    select RegExp_Replace(a.str,
           '(,|^)( *)' || b.befo || '( *)(,|$)',
           '\1\2' || b.aft || '\3\4'),1
      from t a,repstr b
    where b.ID=1
    union all
    select RegExp_Replace(a.str,
           '(,|^)( *)' || b.befo || '( *)(,|$)',
           '\1\2' || b.aft || '\3\4'),a.LV+1
      from rec a,repstr b
    where a.LV+1 = b.ID)
    select max(str) Keep(Dense_Rank Last order by LV) as str
      from rec;
    STR
    1, ,3, , , X, ,Y,234, , , Z ,1 ,4

  • Need some help with the Select query.

    Need some help with the Select query.
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    select single vkorg abgru from ZADS into it_rej.
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
            VKORG TYPE VBAK-VKORG,
            ABGRU TYPE VBAP-ABGRU,
           END OF IT_REJ.
    This is causing performance issue. They are asking me to include the where condition for this select query.
    What should be my select query here?
    Please suggest....
    Any suggestion will be apprecaiated!
    Regards,
    Developer

    Hello Everybody!
    Thank you for all your response!
    I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table 
    select vkorg abgru from ZADS into it_rej.
    Earlier :
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    Now :
    DATA : BEGIN OF IT_REJ occurs 0,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    I guess this will fix the issue correct?
    PLease suggest!
    Regards,
    Developer.

  • I am getting "Invalid Identifier" while running the below query

    Iam getting the error "Invalid Identifier, c_rank" while running the below query. Please help.
    select a.*, b.pog_description pog_description, b.start_date,
    row_number() over(partition by b.pog_description order by b.start_date) c_rank
    from temp_codi_dept_35 a, pog_master_msi b, pog_skus_msi c
    where a.sku = c.pog_sku
    and b.pog_id = c.pog_id
    and b.pog_dept = c.pog_dept
    and b.pog_number = c.pog_number
    and b.pog_level = c.pog_level
    and a.sku = 10263477
    and c_rank = 1;

    >
    Iam getting the error "Invalid Identifier, c_rank" while running the below query. Please help.
    select a.*, b.pog_description pog_description, b.start_date,
    row_number() over(partition by b.pog_description order by b.start_date) c_rank
    from temp_codi_dept_35 a, pog_master_msi b, pog_skus_msi c
    where a.sku = c.pog_sku
    and b.pog_id = c.pog_id
    and b.pog_dept = c.pog_dept
    and b.pog_number = c.pog_number
    and b.pog_level = c.pog_level
    and a.sku = 10263477
    and c_rank = 1;
    >
    You can't use 'c_rank' in the where clause because it doesn't exist; you are computing it in the SELECT clause.
    Remove the last condition and wrap your query in another one to select by 'c_rank'.

  • Need help in tune this query.

    Hi All,
    The below query is taking nearly one hour to give the output.
      2  select sku.VK_UNIT
      3       , sku.MODEL
      4       , sku.DESCRIPTION
      5       , slt.GEO
      6       , slt.LEAD_TIME
      7       , slt.REV_LEAD_TIME
      8       , aud.LEAD_TIME        as PREV_LEAD_TIME_GEO
      9       , aud.REV_LEAD_TIME    as PREV_REV_LEAD_TIME_GEO
    10       , slt.COUNTDOWN
    11       , aud.CREATION_DATE    as EDD_CREATION_DATE_GEO
    12       , aud.CREATED_BY       as EDD_CREATED_BY_GEO
    13    from LTC_GLOBAL.LTC_SKU sku
    14       , LTC_GLOBAL.LTC_SKU_LEAD_TIME slt
    15       , (select VK_UNIT
    16               , MODEL
    17               , substr(ACTION_TYPE, 9) as GEO
    18               , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU EDD ' then ACTION_VALUE  else null end) as LEAD_TIME
    19               , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU EDD ' then CREATION_DATE else null end) as CREATION_DATE
    20               , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU EDD ' then CREATED_BY    else null end) as CREATED_BY
    21               , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU RDD ' then ACTION_VALUE  else null end) as REV_LEAD_TIME
    22               , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU RDD ' then CREATION_DATE else null end) as REV_CREATION_DATE
    23               , max(case when substr(ACTION_TYPE, 1, 8) = 'SKU RDD ' then CREATED_BY    else null end) as REV_CREATED_BY
    24            from (select VK_UNIT
    25                       , MODEL
    26                       , ACTION_TYPE
    27                       , ACTION_VALUE
    28                       , CREATION_DATE
    29                       , CREATED_BY
    30                       , PREV_ACTION_VALUE
    31                       , PREV_CREATION_DATE
    32                       , PREV_CREATED_BY
    33                    from (select
    34                                 NOTE         as VK_UNIT
    35                               , NOTE2        as MODEL
    36                               , ACTION_TYPE
    37                               , ACTION_VALUE
    38                               , CREATION_DATE
    39                               , CREATED_BY
    40                               , row_number()        over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as DEPTH
    41                               , lead(CREATION_DATE) over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as PREV_CREATION_DATE
    42                               , lead(CREATED_BY   ) over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as PREV_CREATED_BY
    43                               , lead(ACTION_VALUE ) over(partition by NOTE, NOTE2, ACTION_TYPE order by CREATION_DATE desc) as PREV_ACTION_VALUE
    44                            from LTC_GLOBAL.LTC_AUDIT
    45                           where NOTE is not null
    46                             and NOTE2 is not null
    47                             and ACTION_TYPE is not null
    48                         )
    49                   where DEPTH = 2
    50                     and substr(ACTION_TYPE, 1, 8) in ('SKU EDD ', 'SKU RDD ')
    51                 )
    52           group by VK_UNIT, MODEL, substr(ACTION_TYPE, 9)
    53         ) aud
    54  where slt.VK_UNIT = sku.VK_UNIT
    55     and slt.MODEL   = sku.MODEL
    56     and slt.CLASS   = sku.CLASS
    57     and nvl(slt.LEAD_TIME, slt.REV_LEAD_TIME) is not null
    58     and aud.VK_UNIT (+)= slt.VK_UNIT
    59     and aud.MODEL   (+)= slt.MODEL
    60     and aud.GEO     (+)= slt.GEO;
    PLAN_TABLE_OUTPUT
    Plan hash value: 2687821083
    | Id  | Operation                   | Name              | Rows  | Bytes |TempSpc| Cost (%CPU)| Time  |
    |   0 | SELECT STATEMENT            |                   |   539K|   902M|       |  1005K  (1)| 03:21:05 |
    |*  1 |  HASH JOIN OUTER            |                   |   539K|   902M|    62M|  1005K  (1)| 03:21:05 |
    |*  2 |   HASH JOIN                 |                   |   539K|    56M|    27M| 66402   (1)| 00:13:17 |
    |*  3 |    TABLE ACCESS FULL        | LTC_SKU_LEAD_TIME |   559K|    20M|       | 23201   (2)| 00:04:39 |
    |   4 |    TABLE ACCESS FULL        | LTC_SKU_UNIT      |  5726K|   382M|       | 19570   (1)| 00:03:55 |
    |   5 |   VIEW                      |                   |  4157K|  6522M|       |   610K  (2)| 02:02:02 |
    PLAN_TABLE_OUTPUT
    |   6 |    HASH GROUP BY            |                   |  4157K|   229M|   303M|   610K  (2)| 02:02:02 |
    |*  7 |     VIEW                    |                   |  4157K|   229M|       |   551K  (2)| 01:50:21 |
    |*  8 |      WINDOW SORT PUSHED RANK|                   |  4157K|   229M|   303M|   551K  (2)| 01:50:21 |
    |*  9 |       TABLE ACCESS FULL     | LTC_AUDIT         |  4157K|   229M|       |   493K  (2)| 01:38:41 |
    Predicate Information (identified by operation id):
       1 - access("AUD"."VK_UNIT"(+)="SLT"."VK_UNIT" AND "AUD"."MODEL"(+)="SLT"."MODEL" AND
                  "AUD"."GEO"(+)="SLT"."GEO")
    PLAN_TABLE_OUTPUT
       2 - access("SLT"."VK_UNIT"="UNIT"."VK_UNIT" AND "SLT"."MODEL"="UNIT"."MODEL" AND
                  "SLT"."CLASS"="UNIT"."CLASS")
       3 - filter(NVL("SLT"."LEAD_TIME","SLT"."REV_LEAD_TIME") IS NOT NULL)
       7 - filter("DEPTH"=2)
       8 - filter(ROW_NUMBER() OVER ( PARTITION BY "NOTE","NOTE2","ACTION_TYPE" ORDER BY
                  INTERNAL_FUNCTION("CREATION_DATE") DESC )<=2)
       9 - filter((SUBSTR("ACTION_TYPE",1,8)='SKU EDD ' OR SUBSTR("ACTION_TYPE",1,8)='SKU RDD ') AND
                  "NOTE2" IS NOT NULL AND "ACTION_TYPE" IS NOT NULL)
    30 rows selected.
    SELECT COUNT(*) FROM LTC_GLOBAL.LTC_SKU--5012335
    SELECT COUNT(*) FROM  LTC_GLOBAL.LTC_SKU_LEAD_TIME--8060956
    SELECT COUNT(*) FROM  LTC_GLOBAL.LTC_AUDIT--58309887
    CREATE UNIQUE INDEX LTC_GLOBAL.LTC_SKU_LEAD_TIME_PK ON LTC_GLOBAL.LTC_SKU_LEAD_TIME(VK_UNIT, MODEL, CLASS, GEO)
    CREATE INDEX LTC_GLOBAL.LTC_AUDIT_LEAD_TIME ON LTC_GLOBAL.LTC_AUDIT(ACTION_TYPE)
    CREATE INDEX LTC_GLOBAL.LTC_AUDIT_LEAD_TIME_DOM ON LTC_GLOBAL.LTC_AUDIT(NOTE, NOTE2, ACTION_TYPE)
    CREATE INDEX LTC_GLOBAL.LTC_AUDIT_LEAD_TIME_DOM1 ON LTC_GLOBAL.LTC_AUDIT("CREATION_DATE" DESC)
    Please help me.
    Thanks in advance.

    Thanks for your response.
    Sorry for violating formatting. Since I am not aware of the format options in new environment.
    I have created functional based index on SUBSTR(ACTION_TYPE, 1, 8).
    The cost got reduced some what.But still the query is taking 40 minutes.
    The following predicate it is returning 58296618 rows.
    NOTE is not null  
    and NOTE2 is not null 
    and ACTION_TYPE is not null 
    LTC_SKU_UNIT is a view.
    The following query is used for creating this view.
       SELECT   unit.VK_UNIT,
                unit.MODEL,
                unit.CLASS,
                unit.LOB,
                unit.LAST_UPDATE_DATE,
                unit.DESCRIPTION
         FROM   LTC_GLOBAL.LTC_SKU_UNIT unit;
    The following indexes are created on the LTC_GLOBAL.LTC_SKU_UNIT table.
    CREATE INDEX LTC_GLOBAL.LTC_SKU_UNIT_IDX_CLASS ON LTC_GLOBAL.LTC_SKU_UNIT(CLASS)
    CREATE INDEX LTC_GLOBAL.LTC_SKU_UNIT_IDX_MODEL ON LTC_GLOBAL.LTC_SKU_UNIT(MODEL)
    CREATE INDEX LTC_GLOBAL.LTC_SKU_UNIT_IDX_UPDATE_DATE ON LTC_GLOBAL.LTC_SKU_UNIT(LAST_UPDATE_DATE)
    CREATE UNIQUE INDEX LTC_GLOBAL.LTC_SKU_UNIT_PK ON LTC_GLOBAL.LTC_SKU_UNIT(VK_UNIT, MODEL, CLASS)
    Is there any way to rewrite the query to improve the performance. Any suggestions to improve the performance.
    Please help me.
    Thanks in advance.

  • Need help with the session state value items.

    I need help with the session state value items.
    Trigger is created (on After delete, insert action) on table A.
    When insert in table B at least one row, then trigger update value to 'Y'
    in table A.
    When delete all rows from a table B,, then trigger update value to 'N'
    in table A.
    In detail report changes are visible, but the trigger replacement value is not set in session value.
    How can I implement this?

    You'll have to create a process which runs after your database update process that does a query and loads the result into your page item.
    For example
    SELECT YN_COLUMN
    FROM My_TABLE
    INTO My_Page_Item
    WHERE Key_value = My_Page_Item_Holding_Key_ValueThe DML process will only return key values after updating, such as an ID primary key updated by a sequence in a trigger.
    If the value is showing in a report, make sure the report refreshes on reload of the page.
    Edited by: Bob37 on Dec 6, 2011 10:36 AM

  • Request for tunning the below query

    Hi,
    Can any one help me on the below query while improving the performance,
    SELECT accdet, acceprec, accinvalid, accnetanal, accphy, accvalid,
    actlabcost, actlabhrs, actualcontactdate, actualfinish, actualstart,
    affecteddate, affectedemail, affectedperson, affectedphone,
    alteration, aslaiddwg, assetnum, assetorgid, assetsiteid,
    assumptions, basedet, basereq, bicounty, bidplo, bieasting,
    bihousename, bihouseno, binorthing, bipobox, bipostcode, biposttown,
    bistreet, bisubb as bisupp, boostcomp, boostcompdet, ccemail, cchouseno, ccid,
    ccname, cctel1type, cctel2type, cctelephone1, cctelephone2, cdm,
    changeby, changedate, CLASS, classstructureid, cocontact, cocounty,
    codplo, coeasment, coeasting, cohousename, conorthing, copobox,
    commodity, commoditygroup, coneasereq, consent, consents,
    copostcode, coposttown, costcon, costreet, cosubb, cpi90,
    createworelasset, customerref, custtype, depot, description, durt,
    ecvpressuretier, ecvsize, enduserid, engdifficult, exaoq, existin,
    existsdq, expid, exshq, externalrecid, extralanddetail, failurecode,
    fr1code, fr2code, fuelpovscheme, g17, gbna, glaccount,
    globalticketclass, globalticketid, govconf, govener, govenerdet,
    govhouse, hasactivity, hasld, historyflag, impact, infill,
    infoprovide, inheritstatus, internalpriority, interquote, isglobal,
    isknownerror, isknownerrordate, kioskdet, kioskreq, langcode,
    latecertdate, leadt, lengthpri, lengthpub, loadtype, LOCATION, m25,
    maindesac, mainusage, meterboxty, metercon, meterloc, meterser,
    mininforec, mininforeq, mprnno, newaoq, newpid, newsdq, newshq,
    np14, nrswa, nsgno, oldquotever, oldticketid, orgid, originsgn,
    origrecordclass, origrecordid, origrecorgid, origrecsiteid, owner,
    ownergroup, packagesent, paymethod, payterms, permittowork, physub,
    pressuretier, privateexc, problemcode, propertiesno, propertytype,
    publicexc, purgerel, quotedate, quotetype, quotever, reinforcement,
    reinforcementa, reinforcementb, relatedtoglobal, reportdate,
    reportedby, reportedemail, reportedphone, reportedpriority,
    rowstamp, sc, scj, scoreq, servicerelay, sgnbillcontact,
    sgnblkbyfin, sgncusttobill, sgncusttosite, sgndisreasoth,
    sgneasment, sgnenhance, sgneow, sgneowreq, sgngqmvalid,
    sgninfillcost, sgninfillver, sgninfprojno, sgnisstdchrg,
    sgnloadnoenter, sgnmainsreq, sgnmaxaccdate, sgnnoncont, sgnpipesiz,
    sgnpurord, sgnqdaysremain, sgnqstd, sgnquotdate, sgnquotval,
    sgnreasdis, sgntotalaoq, sgntotalshq, sgnvarreq, sicontact,
    sicounty, sidplo, sieasting, sihousename, sihouseno, sinorthing,
    sipobox, sipostcode, siposttown, sistreet, sisubb, sitecond, sitegt,
    siteid, sitel1, sitel2, siteplpro, sitevisit, solution, sos,
    sosrecdate, SOURCE, status, statusdate, subfinal, supervisor,
    supplytype, surveycarr, surveydef, surveyreas, surveyreq, surveyret,
    surveysent, targetcontactdate, targetfinish, targetstart, TEMPLATE,
    templateid, termtype, thirdpartyeas, thirdpartypipe, ticketid,
    ticketuid, totalaoq, totalpid, totalsdq, totalshq, traffictime,
    typewo, urgency, variat, vendor, customer_enquiry_ref,
    quote_version, costs, mains_infill_charge, mtr_housing_kiosk_charge,
    mtr_housing_kiosk_base_charge, specialist_reinstatement,
    easement_charge, total_quote_ex_vat, vat, total_quote_incl_vat,
    design_charge, reinforcement_charge, reinforcement_cost,
    connection_allowance, workorder.pscdate, workorder.ascdate,
    workorder.fincode, workorder.istask, workorder.status,
    workorder.targstartdate, workorder.targcompdate,
    workorder.schedfinish, workorder.actfinish, workorder.estdur,
    workorder.wonum, workorder.mprn,
    workorder.sihousename AS wositehousename,
    workorder.sihouseno AS wositehouseno,
    workorder.sistreet AS wositestreet,
    workorder.sicounty AS wositecounty,
    workorder.siposttown AS wositeposttown,
    workorder.sipostcode AS wositepostcode, workorder.workorderid
    FROM (maximo.sr
    INNER JOIN
    (maximo.relatedrecord INNER JOIN maximo.workorder
    ON relatedrecord.relatedreckey =
    (CASE
    WHEN workorder.PARENT IS NOT NULL
    THEN workorder.PARENT
    ELSE workorder.wonum
    END
    AND relatedrecord.orgid = workorder.orgid
    AND relatedrecord.siteid = workorder.siteid
    AND relatedrecord.relatedrecclass = 'WORKORDER')
    ON sr.ticketid = relatedrecord.recordkey
    AND sr.orgid = relatedrecord.orgid
    AND sr.siteid = relatedrecord.siteid
    AND relatedrecord.CLASS = 'SR')
    LEFT JOIN
    frozen_quote@gqmfof
    ON sr.ticketid = customer_enquiry_ref
    AND sr.quotever = quote_version
    Regards,
    grace

    Could you please provide more info.
    Refer to the following link.
    When your query takes too long ...
    thanks

  • HT4528 Hi  I need help with the volume on my phone  even on speaker i can barely hear who I am speaking with

    Hi I need help with the volume on my phone, even on speaker I can barely hear who I am speaking with . How do I make it louder /

    Hi there,
    I would recommend taking a look at the troubleshooting steps found in the article below.
    iPhone: Can't hear through the receiver or speakers
    http://support.apple.com/kb/ts1630
    -Griff W.

Maybe you are looking for

  • Issue w/ Facebook website

    So I bought a 32gb iPad and the first couple of nights I bought it I used the Facebook website chat w/o a problem. The online friends list showed up, I could tap the chat boxes and talk back and forth, etc. Just like I would on a normal desktop brows

  • My Apple TV never completes a download.

    My apple tv used to work fine but now when I try to rent or buy a movie, all I get is the downloading icon spinning endlessly.  The download status bar does not show.  I have it set on low resolution.  Your suggestions as to the problem and a solutio

  • Query Selection Critieria

    Hi experts, My users would like the query selection critieria to allow them to choose a particular selection or select all results For example: Where t0.slpname = [%0] will allow them to select a particular salesperson for the query results. Is there

  • Hacked product photos when online shopping in safari

    This morning, when shopping online via Safari on my iPhone 4S, a very weird thing happened. On several sites (bestbuy.com, jcpenney.com and oldnavy.com) some of the product photos were replaced by random candid shots unrelated to the product. They ar

  • HT1420 i cant authorised my computer with itunes it says u have Authorised 5 computers.

    Well the problem for me is that I authorised old comps but all of them are now not working so i don't know how do i de-authorised them and authorised my current one. PLZZZZZZZZZ help any one.