Query advice & help

I have two Whse's with stock in each.
I'm wondering if a query can be made to show the committed item in Whse "MTL"  with no stock or not enough stock and if there is available stock that can be transferred from the other Whse 'KGN' for that item.
Any help is greatly appreciated

Please try this one:
SELECT t0.itemcode, t0.itemname, t1.OnHand 'MTL On Hand', t1.IsCommited 'MTL Commited', t2.OnHand 'KGN On Hand'FROM dbo.oitm t0
inner join dbo.oitw t1 on t1.itemcode = t0.itemcode and t1.whscode = 'MTL'
inner join dbo.oitw t2 on t2.itemcode = t0.itemcode and t2.whscode = 'KGN'
WHERE (t1.Onhand < t1.IsCommited) and (t2.Onhand >= t1.IsCommited - t1.Onhand)
Thanks,
Gordon

Similar Messages

  • How to improve the performance of the attached query, Please help

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

    Hello,
    This has really nothing to do with the Oracle Forms product.
    Please, send the SQL or/and PL/SQL questions in the corresponding forums.
    Francois

  • Okay I use iPhoto 6 on an older mac and don't want to upgrade past 10.4.11. Can I upgrade iPhoto without the newer operating system? For the life of me I can't get iPhoto to recognize my camera reliably - although it does sometimes. Any advice, help?

    Okay I use iPhoto 6 on an older mac and don't want to upgrade past 10.4.11. Can I upgrade iPhoto without the newer operating system? For the life of me I can't get iPhoto to recognize my camera reliably - although it does sometimes. Any advice, help?

    The latest version of iPhoto which can operation with OS X 10.4.11 is iPhoto 7 which is part of iLife 08.  You might be able to find a copy of iLIfe 08 on Amazon.com or Ebay.com.
    iLife 08's full system requirements are:
    Mac computer with an Intel, PowerPC G5, or PowerPC G4 processor
    iMovie ’08 requires a Mac computer with an Intel processor, a Power Mac G5 (dual 2.0 GHz or faster), or an iMac G5 (1.9 GHz or faster)
    iDVD ’08 requires 733MHz or faster processor
    512 MB of RAM; 1 GB recommended; high-definition video requires at least 1 GB of RAM
    3 GB of available disk space
    DVD drive required for installation
    From: http://support.apple.com/kb/HT1010
    OT

  • Cluster bar chart- sql query please help-

    Hi,
    I am trying to create cluster bar chart and am stumped with this sql query.Any help is appreciated.
    Here is my table
    city     region      issue     value
    c1     north     i1     y
    c1     north     i2     y
    c2     north     i1     n
    c2     north     i2     y
    c3     south     i1     y
    c3     south     i2     n
    c4     east     i1     n
    c4     east     i2     n
    The bar chart will have 3 series, north south and east.
    And labels will be i1 and i2. value will be number of times this issue was encountered(y) in this region.
    How can I get something like this from the above table-
    region     issue     count(yes)
    north     i1     1
    north     i2     2
    south     i1     1
    south     i2     0
    east     i1     0
    east     i2     0
    thanks

    WITH table1 AS
    (SELECT 1435177 qte_id, 2 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no
    FROM dual
    table2 AS
    SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
    FROM dual
    SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
    FROM
    (SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
    FROM table1 t1, table2 t2
    WHERE t2.qte_id = t1.qte_id (+)
    AND t2.seq_no = t1.seq_no(+)
    ORDER BY 1,2
    WHERE t1_seq_no IS NOT NULL
    ORDER BY 1,2
    QTE_ID T2_SEQ_NO DIFF
    1435177 2 0
    1435177 5 0
    1435177 7 0
    1435177 8 0
    1435177 12 0
    1435177 14 0

  • Query question/help

    hi,
    i need some help in trying to create a query to show the table_name, mb_used and degree of parallelism.
    this is what i currently have..
    SELECT a.segment_name, sum(ROUND((BYTEs/1048576*100)/100)) "MB size"
    FROM dba_Segments a
    WHERE a.owner= ??
    and segment_type='TABLE'
    group by segment_name
    order by segment_name;
    select table_name, degree
    from dba_Tables
    where owner='ADW_UTL'
    and tablespace_name is not null
    order by table_name;
    how can i combined the two?
    thanks in advance..

    Hi,
    SELECT a.segment_name, sum(ROUND((BYTEs/1048576*100)/100)) "MB size", b.degree
    FROM dba_Segments a, dba_tables b
    WHERE a.owner= 'xxx'
    and a.owner = b.owner
    and segment_type='TABLE'
    group by segment_name, degree
    order by segment_name;
    Cheers

  • Query Scenario Help - Average of Multiple Regions

    Hi, I have a query scenario I can't create and I hope someone can help with.
    The user inputs a sales Area and the report is to output the regions in that area and provide the Volume (easy) and the Average of all the presented regions.  The problem is that the number of regions is dynamic so I don't know how to go about determining the average and making it constant across the regions.  The user can also drill down on a region to present divisions and I would then need the average for the divisions this time instead of regions.  Can you help?
    Example 1
    Input Sales Area 1000000
    Region               1000001  1000002  1000003
    Product1  Volume       100      120      105
    Product1  Average      108      108      108
    Product2  Volume       200      400      325
    Product2  Average      308      308      308
    Example 2
    Input Sales Area 2000000
    Region               2000001  2000002  2000003  2000004
    Product1  Volume       100      120      105      180
    Product1  Average      126      126      126      126     
    Product2  Volume       200      400      325      600
    Product2  Average      381      381      381      381
    To get this layout I have the following in the query builder:
    The 2 Products are in a structue under Rows
    The Key figures structure is also under Rows
    The Region is under the columns

    If you redesign the report slightly to move the "Average" to a column at the end of each row (which really makes more sense, IMHO), then the answer is easy. Just change the Suppress Results Row property to "Never" for Region, and change the Display Results As property to "Average" for Volume.
    You could also make this same change to Division and/or any other free characteristic they might use as a drill-across in the report.
    Hope this helps...
    Bob

  • Query Tuning-Help Needed

    Hi ,
    11.2.0.1
    AIX 6.1
    I have following query which is executed from Application,the query comes back within 2 secs for not so common last_name combined with gender but it is taking longer time for common last_names like 'BROWN' or 'JONES' or 'SMITH' with gender_id .
    select customerin0_.ROW_NUMBER as ROW1_22596_, customerin0_.ADDRESS_ID as
      ADDRESS2_22596_, customerin0_.addressTypeId as addressT3_22596_,
      customerin0_.city as city22596_, customerin0_.CONTACT_DETAILS_CODE_ID as
      CONTACT5_22596_, customerin0_.county as county22596_, customerin0_.countyID
      as countyID22596_, customerin0_.dob as dob22596_, customerin0_.eyecolor as
      eyecolor22596_, customerin0_.eyecolorid as eyecolorid22596_,
      customerin0_.FIRST_NAME as FIRST11_22596_, customerin0_.gender as
      gender22596_, customerin0_.genderid as genderid22596_,
      customerin0_.ID_NUMBER as ID14_22596_, customerin0_.JURISDICTION_CODE as
      JURISDI15_22596_, customerin0_.LAST_NAME as LAST16_22596_,
      customerin0_.LEGAL_ENTITY_ID as LEGAL17_22596_,
      customerin0_.LEGAL_ENTITY_NUMBER as LEGAL18_22596_,
      customerin0_.LEGAL_ENTITY_TYPE as LEGAL19_22596_, customerin0_.MIDDLE_NAME
      as MIDDLE20_22596_, customerin0_.STREET_ADDRESS_1 as STREET21_22596_,
      customerin0_.suffix_value as suffix22_22596_, customerin0_.ZIP_CODE as
      ZIP23_22596_, customerin0_.ZIP_PLUS_4 as ZIP24_22596_
    from
    CUSTOMER_IND_SEARCH_VIEW customerin0_ where (customerin0_.LAST_NAME like :1)
      and customerin0_.genderid=:2 and rownum<=200
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch       18      1.88     123.53       8245      12403          0         179
    total       18      1.88     123.53       8245      12403          0         179
    Misses in library cache during parse: 0
    Parsing user id: 135  (???)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      ges message buffer allocation                 259        0.00          0.00
      gc cr grant 2-way                             259        0.00          0.08
      db file sequential read                     10126        1.40        148.07
      SQL*Net message from client                    19        0.02          0.10
      SQL*Net message to client                      18        0.00          0.00
    ********************************************************************************Was not able to generate plan out of tkrprof ,captured it from OEM.
      10 |     NESTED LOOPS                  |                              |   805 | 73255 |  3477   (1)| 00:00:42 |
    |  11 |      NESTED LOOPS                 |                              |   805 | 51520 |  1866   (1)| 00:00:23 |
    |  12 |       NESTED LOOPS                |                              |   805 | 33005 |   254   (0)| 00:00:04 |
    |* 13 |        TABLE ACCESS BY INDEX ROWID| REF_CONTACT_DETAILS          |     1 |    10 |     1   (0)| 00:00:01 |
    |* 14 |         INDEX UNIQUE SCAN         | XAK1_REF_CD_VALUE            |     1 |       |     0   (0)|          |
    |  15 |        TABLE ACCESS BY INDEX ROWID| PERSON_PROFILE_NAMES         |   805 | 24955 |   253   (0)| 00:00:04 |
    |* 16 |         INDEX RANGE SCAN          | IDX$$_D7D50001               |   805 |       |     4   (0)| 00:00:01 |
    |* 17 |       TABLE ACCESS BY INDEX ROWID | PERSON_PROFILE               |     1 |    23 |     2   (0)| 00:00:01 |
    |* 18 |        INDEX UNIQUE SCAN          | XPK_PERSON_PROFILE           |     1 |       |     1   (0)| 00:00:01 |
    |* 19 |      TABLE ACCESS BY INDEX ROWID  | LEGAL_ENTITY                 |     1 |    27 |     2   (0)| 00:00:01 |
    |* 20 |       INDEX UNIQUE SCAN           | XPK_LEGAL_ENTITY             |     1 |       |     1   (0)| 00:00:01 |
    |* 21 |     TABLE ACCESS BY INDEX ROWID   | LEGAL_ENTITY_ADDRESSES       |     1 |    81 |     3   (0)| 00:00:01 |
    |* 22 |      INDEX RANGE SCAN             | LENUM_CODE_ID                |     1 |       |     2   (0)| 00:00:01 |
    |* 23 |    TABLE ACCESS BY INDEX ROWID    | LEGAL_ENTITY_IDENTIFICATIONS |     1 |    36 |     3   (0)| 00:00:01 |
    |* 24 |     INDEX RANGE SCAN              | XIF1_LEGAL_ENTITY_ID         |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("REFCOUNTIES"."ID"=:B1)
       4 - access("REFEYECOLORS"."ID"=:B1)
       6 - access("REFGENDER"."ID"=:B1)
       7 - filter(ROWNUM<=200)
      13 - filter("REFCONTACTDETAILS"."MODE_TYPE"=4)
      14 - access("REFCONTACTDETAILS"."VALUE"='PRA')
      16 - access("PERSONPROFILENAMES"."LAST_NAME" LIKE :1 AND "PERSONPROFILENAMES"."IS_DELETED"=0)
           filter(("PERSONPROFILENAMES"."LAST_NAME" LIKE :1 AND "PERSONPROFILENAMES"."IS_DELETED"=0))
      17 - filter("SYS_ALIAS_2"."GENDER_ID"=:2)
      18 - access("SYS_ALIAS_2"."PP_LEGALENTITY_NUMBER"="PERSONPROFILENAMES"."PP_LEGALENTITY_NUMBER")
      19 - filter(("LEGALENTITY"."IS_DELETED"=0 OR "LEGALENTITY"."IS_DELETED"=NULL))
      20 - access("LEGALENTITY"."LEGAL_ENTITY_NUMBER"="SYS_ALIAS_2"."PP_LEGALENTITY_NUMBER")
      21 - filter("LEGALENTITYADDRESSES"."IS_DELETED"=0)
      22 - access("LEGALENTITY"."LEGAL_ENTITY_NUMBER"="LEGALENTITYADDRESSES"."LEGAL_ENTITY_NUMBER" AND
                  "REFCONTACTDETAILS"."ID"="LEGALENTITYADDRESSES"."CONTACT_DETAILS_CODE_ID")
      23 - filter(("LEGAL_ENTITY_ID"."END_DATE">=SYSDATE@! AND "LEGAL_ENTITY_ID"."EFFECTIVE_DATE"<=SYSDATE@!))
      24 - access("LEGAL_ENTITY_ID"."LEGAL_ENTITY_NUMBER"="LEGALENTITY"."LEGAL_ENTITY_NUMBER")
      Please advice ....
    Thanks
    Edited by: Monto on Aug 22, 2012 4:22 AM

    Explain Plan with common name.
    SELECT  customerin0_.ROW_NUMBER AS ROW1_22596_,
             customerin0_.ADDRESS_ID AS ADDRESS2_22596_,
             customerin0_.addressTypeId AS addressT3_22596_,
             customerin0_.city AS city22596_,
             customerin0_.CONTACT_DETAILS_CODE_ID AS CONTACT5_22596_,
             customerin0_.county AS county22596_,
             customerin0_.countyID AS countyID22596_,
             customerin0_.dob AS dob22596_,
             customerin0_.eyecolor AS eyecolor22596_,
             customerin0_.eyecolorid AS eyecolorid22596_,
             customerin0_.FIRST_NAME AS FIRST11_22596_,
             customerin0_.gender AS gender22596_,
             customerin0_.genderid AS genderid22596_,
             customerin0_.ID_NUMBER AS ID14_22596_,
             customerin0_.JURISDICTION_CODE AS JURISDI15_22596_,
             customerin0_.LAST_NAME AS LAST16_22596_,
             customerin0_.LEGAL_ENTITY_ID AS LEGAL17_22596_,
             customerin0_.LEGAL_ENTITY_NUMBER AS LEGAL18_22596_,
             customerin0_.LEGAL_ENTITY_TYPE AS LEGAL19_22596_,
             customerin0_.MIDDLE_NAME AS MIDDLE20_22596_,
             customerin0_.STREET_ADDRESS_1 AS STREET21_22596_,
             customerin0_.suffix_value AS suffix22_22596_,
             customerin0_.ZIP_CODE AS ZIP23_22596_,
             customerin0_.ZIP_PLUS_4 AS ZIP24_22596_
      FROM   xmatapp.CUSTOMER_IND_SEARCH_VIEW customerin0_
    WHERE   (customerin0_.LAST_NAME LIKE 'SMITH%')
             AND customerin0_.genderid = 2
             AND ROWNUM <= 200
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.04       0.05          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       15      5.05     167.51      14050      20246          0         200
    total       17      5.09     167.56      14050      20246          0         200
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows     Row Source Operation
         41  TABLE ACCESS BY INDEX ROWID REF_COUNTIES (cr=58 pr=0 pw=0 time=0 us cost=1 size=12 card=1)
         41   INDEX UNIQUE SCAN XPK_REF_COUNTIES (cr=17 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308432)
          7  TABLE ACCESS BY INDEX ROWID REF_EYE_COLORS (cr=11 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          7   INDEX UNIQUE SCAN XPK_REF_EYE_COLORS (cr=4 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308404)
          1  TABLE ACCESS BY INDEX ROWID REF_GENDER (cr=2 pr=0 pw=0 time=0 us cost=1 size=9 card=1)
          1   INDEX UNIQUE SCAN XPK_REF_GENDER (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308759)
        200  COUNT STOPKEY (cr=20175 pr=14050 pw=0 time=2540633 us)
        200   NESTED LOOPS OUTER (cr=20175 pr=14050 pw=0 time=2540633 us cost=103 size=1248 card=6)
        200    NESTED LOOPS  (cr=19756 pr=13775 pw=0 time=17003952 us cost=80 size=1032 card=6)
        200     NESTED LOOPS  (cr=19304 pr=13586 pw=0 time=14271285 us cost=55 size=1092 card=12)
        200      NESTED LOOPS  (cr=19017 pr=13453 pw=0 time=13593988 us cost=31 size=768 card=12)
       4923       NESTED LOOPS  (cr=4640 pr=4614 pw=0 time=63281900 us cost=7 size=492 card=12)
          1        TABLE ACCESS BY INDEX ROWID REF_CONTACT_DETAILS (cr=2 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          1         INDEX UNIQUE SCAN XAK1_REF_CD_VALUE (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308425)
       4923        TABLE ACCESS BY INDEX ROWID PERSON_PROFILE_NAMES (cr=4638 pr=4614 pw=0 time=63269280 us cost=6 size=372 card=12)
       4923         INDEX RANGE SCAN IDX$$_D7D50001 (cr=30 pr=16 pw=0 time=60326 us cost=2 size=0 card=12)(object id 311149)
        200       TABLE ACCESS BY INDEX ROWID PERSON_PROFILE (cr=14377 pr=8839 pw=0 time=0 us cost=2 size=23 card=1)
       4923        INDEX UNIQUE SCAN XPK_PERSON_PROFILE (cr=9454 pr=4288 pw=0 time=0 us cost=1 size=0 card=1)(object id 308484)
        200      TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY (cr=287 pr=133 pw=0 time=0 us cost=2 size=27 card=1)
        200       INDEX UNIQUE SCAN XPK_LEGAL_ENTITY (cr=225 pr=80 pw=0 time=0 us cost=1 size=0 card=1)(object id 308494)
        200     TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_ADDRESSES (cr=452 pr=189 pw=0 time=0 us cost=3 size=81 card=1)
        200      INDEX RANGE SCAN LENUM_CODE_ID (cr=281 pr=94 pw=0 time=0 us cost=2 size=0 card=1)(object id 307952)
        200    TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_IDENTIFICATIONS (cr=419 pr=275 pw=0 time=0 us cost=4 size=36 card=1)
        200     INDEX RANGE SCAN XIF1_LEGAL_ENTITY_ID (cr=219 pr=77 pw=0 time=0 us cost=2 size=0 card=1)(object id 308082)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      ges message buffer allocation                8576        0.00          0.02
      library cache lock                              7        0.00          0.00
      library cache pin                               7        0.00          0.00
      SQL*Net message to client                      15        0.00          0.00
      Disk file operations I/O                       19        0.01          0.03
      gc cr grant 2-way                            8554        0.01          3.09
      db file sequential read                     14050        0.91        158.32
      SQL*Net message from client                    15       32.28         35.97
      gc cr grant congested                           8        0.00          0.01
    ********************************************************************************Plan with rare names.
    SELECT   customerin0_.ROW_NUMBER AS ROW1_22596_,
             customerin0_.ADDRESS_ID AS ADDRESS2_22596_,
             customerin0_.addressTypeId AS addressT3_22596_,
             customerin0_.city AS city22596_,
             customerin0_.CONTACT_DETAILS_CODE_ID AS CONTACT5_22596_,
             customerin0_.county AS county22596_,
             customerin0_.countyID AS countyID22596_,
             customerin0_.dob AS dob22596_,
             customerin0_.eyecolor AS eyecolor22596_,
             customerin0_.eyecolorid AS eyecolorid22596_,
             customerin0_.FIRST_NAME AS FIRST11_22596_,
             customerin0_.gender AS gender22596_,
             customerin0_.genderid AS genderid22596_,
             customerin0_.ID_NUMBER AS ID14_22596_,
             customerin0_.JURISDICTION_CODE AS JURISDI15_22596_,
             customerin0_.LAST_NAME AS LAST16_22596_,
             customerin0_.LEGAL_ENTITY_ID AS LEGAL17_22596_,
             customerin0_.LEGAL_ENTITY_NUMBER AS LEGAL18_22596_,
             customerin0_.LEGAL_ENTITY_TYPE AS LEGAL19_22596_,
             customerin0_.MIDDLE_NAME AS MIDDLE20_22596_,
             customerin0_.STREET_ADDRESS_1 AS STREET21_22596_,
             customerin0_.suffix_value AS suffix22_22596_,
             customerin0_.ZIP_CODE AS ZIP23_22596_,
             customerin0_.ZIP_PLUS_4 AS ZIP24_22596_
      FROM   xmatapp.CUSTOMER_IND_SEARCH_VIEW customerin0_
    WHERE       (customerin0_.LAST_NAME LIKE 'KUMAR%')
             AND customerin0_.genderid = '2'
             AND ROWNUM <= 200
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.05       0.07          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       15      0.02       0.03          0       1829          0         200
    total       17      0.07       0.10          0       1829          0         200
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows     Row Source Operation
         23  TABLE ACCESS BY INDEX ROWID REF_COUNTIES (cr=37 pr=0 pw=0 time=0 us cost=1 size=12 card=1)
         23   INDEX UNIQUE SCAN XPK_REF_COUNTIES (cr=14 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308432)
          5  TABLE ACCESS BY INDEX ROWID REF_EYE_COLORS (cr=9 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          5   INDEX UNIQUE SCAN XPK_REF_EYE_COLORS (cr=4 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308404)
          1  TABLE ACCESS BY INDEX ROWID REF_GENDER (cr=2 pr=0 pw=0 time=0 us cost=1 size=9 card=1)
          1   INDEX UNIQUE SCAN XPK_REF_GENDER (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308759)
        200  COUNT STOPKEY (cr=1781 pr=0 pw=0 time=15124 us)
        200   NESTED LOOPS OUTER (cr=1781 pr=0 pw=0 time=14726 us cost=103 size=1248 card=6)
        200    NESTED LOOPS  (cr=1383 pr=0 pw=0 time=35422 us cost=80 size=1032 card=6)
        200     NESTED LOOPS  (cr=980 pr=0 pw=0 time=20198 us cost=55 size=1092 card=12)
        200      NESTED LOOPS  (cr=741 pr=0 pw=0 time=15422 us cost=31 size=768 card=12)
        289       NESTED LOOPS  (cr=129 pr=0 pw=0 time=3648 us cost=7 size=492 card=12)
          1        TABLE ACCESS BY INDEX ROWID REF_CONTACT_DETAILS (cr=2 pr=0 pw=0 time=0 us cost=1 size=10 card=1)
          1         INDEX UNIQUE SCAN XAK1_REF_CD_VALUE (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card=1)(object id 308425)
        289        TABLE ACCESS BY INDEX ROWID PERSON_PROFILE_NAMES (cr=127 pr=0 pw=0 time=3360 us cost=6 size=372 card=12)
        289         INDEX RANGE SCAN IDX$$_D7D50001 (cr=18 pr=0 pw=0 time=672 us cost=2 size=0 card=12)(object id 311149)
        200       TABLE ACCESS BY INDEX ROWID PERSON_PROFILE (cr=612 pr=0 pw=0 time=0 us cost=2 size=23 card=1)
        289        INDEX UNIQUE SCAN XPK_PERSON_PROFILE (cr=323 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 308484)
        200      TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY (cr=239 pr=0 pw=0 time=0 us cost=2 size=27 card=1)
        200       INDEX UNIQUE SCAN XPK_LEGAL_ENTITY (cr=194 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 308494)
        200     TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_ADDRESSES (cr=403 pr=0 pw=0 time=0 us cost=3 size=81 card=1)
        200      INDEX RANGE SCAN LENUM_CODE_ID (cr=230 pr=0 pw=0 time=0 us cost=2 size=0 card=1)(object id 307952)
        200    TABLE ACCESS BY INDEX ROWID LEGAL_ENTITY_IDENTIFICATIONS (cr=398 pr=0 pw=0 time=0 us cost=4 size=36 card=1)
        200     INDEX RANGE SCAN XIF1_LEGAL_ENTITY_ID (cr=198 pr=0 pw=0 time=0 us cost=2 size=0 card=1)(object id 308082)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      ges message buffer allocation                  14        0.00          0.00
      library cache lock                              7        0.00          0.00
      library cache pin                               7        0.00          0.00
      KJC: Wait for msg sends to complete             2        0.00          0.00
      SQL*Net message to client                      15        0.00          0.00
      SQL*Net message from client                    15       18.88         21.81
    ********************************************************************************PERSONPROFILENAMES-16 Milion rows
    LEGALENTITYADDRESSES-34 Milion rows
    PERSONPROFILE-16 Milion rows
    LEGALENTITY 17 Milion rows
    refcontactdetails 45 rows
    Thanks

  • Query HINT help requested Pls.

    A query thus:
    SELECT equipment_id,
    vsemml.stock_equipment_id,
    game_ware_id
    FROM v_stocked_equipment_inven_his vsdeih,
    v_stock_equipment_mod_man_list vsemml
    WHERE vsemml.stock_equipment_id = vsdeih.stock_equipment_id(+)
    AND equipment_status_code IN
    ('ALL', 'AVA' )
    AND ec_end_date IS NULL
    AND eav_end_date IS NULL
    GROUP BY equipment_id,
    vsemml.stock_equipment_id,
    game_ware_id
    HAVING COUNT (model_attribute_value_id) =
    (SELECT COUNT (*)
    FROM stock_equipment JOIN stock_equipment_attrib_value
    USING (stock_equipment_id)
    WHERE stock_equipment_id =
    vsemml.stock_equipment_id);
    has result :
    513 rows selected.
    Elapsed: 00:04:59.17
    Execution Plan
    Plan hash value: 3816309895
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 240 | 21120 | | 38010 (7)| 00:07:37 |
    |* 1 | FILTER | | | | | | |
    | 2 | HASH GROUP BY | | 240 | 21120 | | 38010 (7)| 00:07:37 |
    |* 3 | FILTER | | | | | | |
    |* 4 | HASH JOIN OUTER | | 23915 | 2055K| | 38006 (7)| 00:07:37 |
    |* 5 | HASH JOIN | | 42 | 630 | | 7 (15)| 00:00:01 |
    | 6 | TABLE ACCESS FULL | MODEL | 31 | 279 | | 3 (0)| 00:00:01 |
    | 7 | TABLE ACCESS FULL | STOCK_EQUIPMENT | 42 | 252 | | 3 (0)| 00:00:01 |
    | 8 | VIEW | V_STOCKED_EQUIPMENT_INVEN_HIS | 23915 | 1704K| | 37998 (7)| 00:07:36 |
    | 9 | HASH UNIQUE | | 23915 | 2989K| 6392K| 37998 (7)| 00:07:36 |
    |* 10 | HASH JOIN RIGHT OUTER | | 23915 | 2989K| | 37307 (7)| 00:07:28 |
    | 11 | TABLE ACCESS FULL | GAME_WARE | 325 | 1950 | | 3 (0)| 00:00:01 |
    |* 12 | HASH JOIN RIGHT OUTER | | 23915 | 2849K| | 37303 (7)| 00:07:28 |
    | 13 | TABLE ACCESS FULL | GAMESET | 825 | 8250 | | 5 (0)| 00:00:01 |
    |* 14 | HASH JOIN | | 23915 | 2615K| | 37297 (7)| 00:07:28 |
    | 15 | TABLE ACCESS FULL | EQUIPMENT_STATUS | 16 | 128 | | 3 (0)| 00:00:01 |
    |* 16 | HASH JOIN | | 23915 | 2428K| | 37293 (7)| 00:07:28 |
    | 17 | TABLE ACCESS FULL | STOCK_EQUIPMENT | 42 | 252 | | 3 (0)| 00:00:01 |
    |* 18 | HASH JOIN | | 645K| 60M| | 37278 (7)| 00:07:28 |
    | 19 | INDEX FULL SCAN | XPKSTOCK_EQUIPMENT_ATTRIB_VAL | 42 | 294 | | 1 (0)| 00:00:01 |
    |* 20 | HASH JOIN | | 5288K| 458M| 9M| 37180 (7)| 00:07:27 |
    | 21 | TABLE ACCESS FULL | EQUIPMENT_ATTRIBUTE_VALUE | 297K| 6672K| | 784 (3)| 00:00:10 |
    |* 22 | HASH JOIN | | 7467K| 484M| 6328K| 5447 (5)| 00:01:06 |
    | 23 | INDEX FAST FULL SCAN | PK_EQUIPMENT_CONFIGURATION | 380K| 1859K| | 398 (3)| 00:00:05 |
    |* 24 | HASH JOIN | | 380K| 22M| 4528K| 3235 (2)| 00:00:39 |
    |* 25 | HASH JOIN | | 140K| 2876K| | 563 (2)| 00:00:07 |
    | 26 | MERGE JOIN | | 281 | 3372 | | 6 (17)| 00:00:01 |
    | 27 | TABLE ACCESS BY INDEX ROWID| SITE_TYPE | 4 | 20 | | 2 (0)| 00:00:01 |
    | 28 | INDEX FULL SCAN | PK_SITE_TYPE | 4 | | | 1 (0)| 00:00:01 |
    |* 29 | SORT JOIN | | 281 | 1967 | | 4 (25)| 00:00:01 |
    | 30 | VIEW | index$_join$_016 | 281 | 1967 | | 3 (0)| 00:00:01 |
    |* 31 | HASH JOIN | | | | | | |
    | 32 | INDEX FAST FULL SCAN | PK_SITE | 281 | 1967 | | 1 (0)| 00:00:01 |
    | 33 | INDEX FAST FULL SCAN | XIF1SITE | 281 | 1967 | | 1 (0)| 00:00:01 |
    | 34 | TABLE ACCESS FULL | LOCATION | 140K| 1232K| | 554 (2)| 00:00:07 |
    | 35 | TABLE ACCESS FULL | EQUIPMENT_CONFIGURATION | 380K| 15M| | 1460 (2)| 00:00:18 |
    | 36 | SORT AGGREGATE | | 1 | 6 | | | |
    | 37 | NESTED LOOPS | | 1 | 6 | | 0 (0)| 00:00:01 |
    |* 38 | INDEX UNIQUE SCAN | XPKSTOCK_EQUIPMENT | 1 | 3 | | 0 (0)| 00:00:01 |
    |* 39 | INDEX RANGE SCAN | XIF1STOCK_EQUIPMENT_ATTRIB_VAL | 1 | 3 | | 0 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - filter(COUNT("MODEL_ATTRIBUTE_VALUE_ID")= (SELECT COUNT(*) FROM "STOCK_EQUIPMENT_ATTRIB_VALUE"
    "STOCK_EQUIPMENT_ATTRIB_VALUE","STOCK_EQUIPMENT" "STOCK_EQUIPMENT" WHERE "STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"=:B1 AND
    "STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID" AND
    "STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID"=:B2))
    3 - filter(("EQUIPMENT_STATUS_CODE"='ALL' OR "EQUIPMENT_STATUS_CODE"='AVA') AND "EC_END_DATE" IS NULL AND "EAV_END_DATE"
    IS NULL)
    4 - access("SE"."STOCK_EQUIPMENT_ID"="VSDEIH"."STOCK_EQUIPMENT_ID"(+))
    5 - access("SE"."MODEL_ID"="M"."MODEL_ID")
    10 - access("GS"."GAME_WARE_ID"="GW"."GAME_WARE_ID"(+))
    12 - access("EC"."GAMESET_ID"="GS"."GAMESET_ID"(+))
    14 - access("EC"."EQUIPMENT_STATUS_ID"="ES"."EQUIPMENT_STATUS_ID")
    16 - access("EC"."MODEL_ID"="STOCK_EQUIPMENT"."MODEL_ID" AND
    "STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID")
    18 - access("MODEL_ATTRIBUTE_VALUE_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."MODEL_ATTRIBUTE_VALUE_ID")
    20 - access("EC"."EQUIPMENT_ID"="EAV"."EQUIPMENT_ID")
    filter("EAV"."START_DATE">="EC"."START_DATE" AND ("EAV"."END_DATE" IS NULL AND "EC"."END_DATE">="EAV"."START_DATE" OR
    "EC"."END_DATE" IS NULL OR "EAV"."END_DATE"<="EC"."END_DATE") OR "EC"."START_DATE">="EAV"."START_DATE" AND ("EC"."END_DATE"
    IS NULL AND "EAV"."END_DATE">="EC"."START_DATE" OR "EAV"."END_DATE" IS NULL OR "EC"."END_DATE"<="EAV"."END_DATE"))
    22 - access("EC"."EQUIPMENT_ID"="EC"."EQUIPMENT_ID")
    24 - access("EC"."LOCATION_ID"="L"."LOCATION_ID")
    25 - access("L"."SITE_ID"="S"."SITE_ID")
    29 - access("S"."SITE_TYPE_ID"="ST"."SITE_TYPE_ID")
    filter("S"."SITE_TYPE_ID"="ST"."SITE_TYPE_ID")
    31 - access(ROWID=ROWID)
    38 - access("STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"=:B1)
    39 - access("STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID")
    filter("STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID"=:B1)
    Query altered to:
    =================
    SELECT equipment_id,
    vsemml.stock_equipment_id,
    game_ware_id
    FROM v_stocked_equipment_inven_his vsdeih,
    v_stock_equipment_mod_man_list vsemml
    WHERE vsemml.stock_equipment_id = vsdeih.stock_equipment_id(+)
    AND equipment_status_code = 'ALL'
    AND ec_end_date IS NULL
    AND eav_end_date IS NULL
    GROUP BY equipment_id,
    vsemml.stock_equipment_id,
    game_ware_id
    HAVING COUNT (model_attribute_value_id) =
    (SELECT COUNT (*)
    FROM stock_equipment JOIN stock_equipment_attrib_value
    USING (stock_equipment_id)
    WHERE stock_equipment_id =
    vsemml.stock_equipment_id)
    union
    SELECT equipment_id,
    vsemml.stock_equipment_id,
    game_ware_id
    FROM v_stocked_equipment_inven_his vsdeih,
    v_stock_equipment_mod_man_list vsemml
    WHERE vsemml.stock_equipment_id = vsdeih.stock_equipment_id(+)
    AND equipment_status_code = 'AVA'
    AND ec_end_date IS NULL
    AND eav_end_date IS NULL
    GROUP BY equipment_id,
    vsemml.stock_equipment_id,
    game_ware_id
    HAVING COUNT (model_attribute_value_id) =
    (SELECT COUNT (*)
    FROM stock_equipment JOIN stock_equipment_attrib_value
    USING (stock_equipment_id)
    WHERE stock_equipment_id =
    vsemml.stock_equipment_id);
    Results in:
    513 rows selected.
    Elapsed: 00:00:07.40
    Execution Plan
    Plan hash value: 3317078232
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 2 | 176 | | 6431 (51)| 00:01:18 |
    | 1 | SORT UNIQUE | | 2 | 176 | | 6431 (51)| 00:01:18 |
    | 2 | UNION-ALL | | | | | | |
    |* 3 | FILTER | | | | | | |
    | 4 | HASH GROUP BY | | 1 | 88 | | 3216 (2)| 00:00:39 |
    |* 5 | HASH JOIN | | 95 | 8360 | | 3214 (2)| 00:00:39 |
    |* 6 | HASH JOIN | | 42 | 630 | | 7 (15)| 00:00:01 |
    | 7 | TABLE ACCESS FULL | MODEL | 31 | 279 | | 3 (0)| 00:00:01 |
    | 8 | TABLE ACCESS FULL | STOCK_EQUIPMENT | 42 | 252 | | 3 (0)| 00:00:01 |
    | 9 | VIEW | V_STOCKED_EQUIPMENT_INVEN_HIS | 95 | 6935 | | 3207 (2)| 00:00:39 |
    | 10 | HASH UNIQUE | | 95 | 12160 | | 3207 (2)| 00:00:39 |
    |* 11 | HASH JOIN RIGHT OUTER | | 95 | 12160 | | 3206 (2)| 00:00:39 |
    | 12 | TABLE ACCESS FULL | GAME_WARE | 325 | 1950 | | 3 (0)| 00:00:01 |
    |* 13 | HASH JOIN OUTER | | 95 | 11590 | | 3202 (2)| 00:00:39 |
    |* 14 | HASH JOIN | | 95 | 10640 | | 3196 (2)| 00:00:39 |
    | 15 | TABLE ACCESS FULL | SITE_TYPE | 4 | 20 | | 3 (0)| 00:00:01 |
    |* 16 | HASH JOIN | | 95 | 10165 | | 3193 (2)| 00:00:39 |
    | 17 | VIEW | index$_join$_021 | 281 | 1967 | | 3 (0)| 00:00:01 |
    |* 18 | HASH JOIN | | | | | | |
    | 19 | INDEX FAST FULL SCAN | PK_SITE | 281 | 1967 | | 1 (0)| 00:00:01 |
    | 20 | INDEX FAST FULL SCAN | XIF1SITE | 281 | 1967 | | 1 (0)| 00:00:01 |
    | 21 | NESTED LOOPS | | 95 | 9500 | | 3189 (2)| 00:00:39 |
    |* 22 | HASH JOIN | | 96 | 8736 | 4440K| 3093 (2)| 00:00:38 |
    |* 23 | HASH JOIN | | 56789 | 3771K| | 1679 (2)| 00:00:21 |
    |* 24 | HASH JOIN | | 2894 | 178K| | 1273 (1)| 00:00:16 |
    | 25 | INDEX FULL SCAN | XPKSTOCK_EQUIPMENT_ATTRIB_VAL | 42 | 294 | | 1 (0)| 00:00:01 |
    |* 26 | HASH JOIN | | 2894 | 158K| | 1271 (1)| 00:00:16 |
    | 27 | TABLE ACCESS FULL | STOCK_EQUIPMENT | 42 | 252 | | 3 (0)| 00:00:01 |
    |* 28 | TABLE ACCESS BY INDEX ROWID| EQUIPMENT_CONFIGURATION | 1279 | 53718 | | 1265 (1)| 00:00:16 |
    | 29 | NESTED LOOPS | | 1860 | 93000 | | 1268 (1)| 00:00:16 |
    |* 30 | TABLE ACCESS FULL | EQUIPMENT_STATUS | 1 | 8 | | 3 (0)| 00:00:01 |
    |* 31 | INDEX RANGE SCAN | XIF3EQUIPMENT_CONFIGURATION | 23796 | | | 48 (3)| 00:00:01 |
    | 32 | INDEX FAST FULL SCAN | PK_EQUIPMENT_CONFIGURATION | 380K| 1859K| | 398 (3)| 00:00:05 |
    |* 33 | TABLE ACCESS FULL | EQUIPMENT_ATTRIBUTE_VALUE | 242K| 5451K| | 785 (3)| 00:00:10 |
    | 34 | TABLE ACCESS BY INDEX ROWID | LOCATION | 1 | 9 | | 1 (0)| 00:00:01 |
    |* 35 | INDEX UNIQUE SCAN | PK_LOCATION | 1 | | | 0 (0)| 00:00:01 |
    | 36 | TABLE ACCESS FULL | GAMESET | 825 | 8250 | | 5 (0)| 00:00:01 |
    | 37 | SORT AGGREGATE | | 1 | 6 | | | |
    | 38 | NESTED LOOPS | | 1 | 6 | | 0 (0)| 00:00:01 |
    |* 39 | INDEX UNIQUE SCAN | XPKSTOCK_EQUIPMENT | 1 | 3 | | 0 (0)| 00:00:01 |
    |* 40 | INDEX RANGE SCAN | XIF1STOCK_EQUIPMENT_ATTRIB_VAL | 1 | 3 | | 0 (0)| 00:00:01 |
    |* 41 | FILTER | | | | | | |
    | 42 | HASH GROUP BY | | 1 | 88 | | 3216 (2)| 00:00:39 |
    |* 43 | HASH JOIN | | 95 | 8360 | | 3214 (2)| 00:00:39 |
    |* 44 | HASH JOIN | | 42 | 630 | | 7 (15)| 00:00:01 |
    | 45 | TABLE ACCESS FULL | MODEL | 31 | 279 | | 3 (0)| 00:00:01 |
    | 46 | TABLE ACCESS FULL | STOCK_EQUIPMENT | 42 | 252 | | 3 (0)| 00:00:01 |
    | 47 | VIEW | V_STOCKED_EQUIPMENT_INVEN_HIS | 95 | 6935 | | 3207 (2)| 00:00:39 |
    | 48 | HASH UNIQUE | | 95 | 12160 | | 3207 (2)| 00:00:39 |
    |* 49 | HASH JOIN RIGHT OUTER | | 95 | 12160 | | 3206 (2)| 00:00:39 |
    | 50 | TABLE ACCESS FULL | GAME_WARE | 325 | 1950 | | 3 (0)| 00:00:01 |
    |* 51 | HASH JOIN OUTER | | 95 | 11590 | | 3202 (2)| 00:00:39 |
    |* 52 | HASH JOIN | | 95 | 10640 | | 3196 (2)| 00:00:39 |
    | 53 | TABLE ACCESS FULL | SITE_TYPE | 4 | 20 | | 3 (0)| 00:00:01 |
    |* 54 | HASH JOIN | | 95 | 10165 | | 3193 (2)| 00:00:39 |
    | 55 | VIEW | index$_join$_044 | 281 | 1967 | | 3 (0)| 00:00:01 |
    |* 56 | HASH JOIN | | | | | | |
    | 57 | INDEX FAST FULL SCAN | PK_SITE | 281 | 1967 | | 1 (0)| 00:00:01 |
    | 58 | INDEX FAST FULL SCAN | XIF1SITE | 281 | 1967 | | 1 (0)| 00:00:01 |
    | 59 | NESTED LOOPS | | 95 | 9500 | | 3189 (2)| 00:00:39 |
    |* 60 | HASH JOIN | | 96 | 8736 | 4440K| 3093 (2)| 00:00:38 |
    |* 61 | HASH JOIN | | 56789 | 3771K| | 1679 (2)| 00:00:21 |
    |* 62 | HASH JOIN | | 2894 | 178K| | 1273 (1)| 00:00:16 |
    | 63 | INDEX FULL SCAN | XPKSTOCK_EQUIPMENT_ATTRIB_VAL | 42 | 294 | | 1 (0)| 00:00:01 |
    |* 64 | HASH JOIN | | 2894 | 158K| | 1271 (1)| 00:00:16 |
    | 65 | TABLE ACCESS FULL | STOCK_EQUIPMENT | 42 | 252 | | 3 (0)| 00:00:01 |
    |* 66 | TABLE ACCESS BY INDEX ROWID| EQUIPMENT_CONFIGURATION | 1279 | 53718 | | 1265 (1)| 00:00:16 |
    | 67 | NESTED LOOPS | | 1860 | 93000 | | 1268 (1)| 00:00:16 |
    |* 68 | TABLE ACCESS FULL | EQUIPMENT_STATUS | 1 | 8 | | 3 (0)| 00:00:01 |
    |* 69 | INDEX RANGE SCAN | XIF3EQUIPMENT_CONFIGURATION | 23796 | | | 48 (3)| 00:00:01 |
    | 70 | INDEX FAST FULL SCAN | PK_EQUIPMENT_CONFIGURATION | 380K| 1859K| | 398 (3)| 00:00:05 |
    |* 71 | TABLE ACCESS FULL | EQUIPMENT_ATTRIBUTE_VALUE | 242K| 5451K| | 785 (3)| 00:00:10 |
    | 72 | TABLE ACCESS BY INDEX ROWID | LOCATION | 1 | 9 | | 1 (0)| 00:00:01 |
    |* 73 | INDEX UNIQUE SCAN | PK_LOCATION | 1 | | | 0 (0)| 00:00:01 |
    | 74 | TABLE ACCESS FULL | GAMESET | 825 | 8250 | | 5 (0)| 00:00:01 |
    | 75 | SORT AGGREGATE | | 1 | 6 | | | |
    | 76 | NESTED LOOPS | | 1 | 6 | | 0 (0)| 00:00:01 |
    |* 77 | INDEX UNIQUE SCAN | XPKSTOCK_EQUIPMENT | 1 | 3 | | 0 (0)| 00:00:01 |
    |* 78 | INDEX RANGE SCAN | XIF1STOCK_EQUIPMENT_ATTRIB_VAL | 1 | 3 | | 0 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    3 - filter(COUNT("MODEL_ATTRIBUTE_VALUE_ID")= (SELECT COUNT(*) FROM "STOCK_EQUIPMENT_ATTRIB_VALUE"
    "STOCK_EQUIPMENT_ATTRIB_VALUE","STOCK_EQUIPMENT" "STOCK_EQUIPMENT" WHERE "STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"=:B1 AND
    "STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID" AND
    "STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID"=:B2))
    5 - access("SE"."STOCK_EQUIPMENT_ID"="VSDEIH"."STOCK_EQUIPMENT_ID")
    6 - access("SE"."MODEL_ID"="M"."MODEL_ID")
    11 - access("GS"."GAME_WARE_ID"="GW"."GAME_WARE_ID"(+))
    13 - access("EC"."GAMESET_ID"="GS"."GAMESET_ID"(+))
    14 - access("S"."SITE_TYPE_ID"="ST"."SITE_TYPE_ID")
    16 - access("L"."SITE_ID"="S"."SITE_ID")
    18 - access(ROWID=ROWID)
    22 - access("MODEL_ATTRIBUTE_VALUE_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."MODEL_ATTRIBUTE_VALUE_ID" AND
    "EC"."EQUIPMENT_ID"="EAV"."EQUIPMENT_ID")
    filter("EAV"."START_DATE">="EC"."START_DATE" AND ("EAV"."END_DATE" IS NULL AND "EC"."END_DATE">="EAV"."START_DATE" OR
    "EC"."END_DATE" IS NULL OR "EAV"."END_DATE"<="EC"."END_DATE") OR "EC"."START_DATE">="EAV"."START_DATE" AND ("EC"."END_DATE"
    IS NULL AND "EAV"."END_DATE">="EC"."START_DATE" OR "EAV"."END_DATE" IS NULL OR "EC"."END_DATE"<="EAV"."END_DATE"))
    23 - access("EC"."EQUIPMENT_ID"="EC"."EQUIPMENT_ID")
    24 - access("STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID")
    26 - access("EC"."MODEL_ID"="STOCK_EQUIPMENT"."MODEL_ID")
    28 - filter("EC"."END_DATE" IS NULL)
    30 - filter("ES"."EQUIPMENT_STATUS_CODE"='ALL')
    31 - access("EC"."EQUIPMENT_STATUS_ID"="ES"."EQUIPMENT_STATUS_ID")
    33 - filter("EAV"."END_DATE" IS NULL)
    35 - access("EC"."LOCATION_ID"="L"."LOCATION_ID")
    39 - access("STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"=:B1)
    40 - access("STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID")
    filter("STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID"=:B1)
    41 - filter(COUNT("MODEL_ATTRIBUTE_VALUE_ID")= (SELECT COUNT(*) FROM "STOCK_EQUIPMENT_ATTRIB_VALUE"
    "STOCK_EQUIPMENT_ATTRIB_VALUE","STOCK_EQUIPMENT" "STOCK_EQUIPMENT" WHERE "STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"=:B1 AND
    "STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID" AND
    "STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID"=:B2))
    43 - access("SE"."STOCK_EQUIPMENT_ID"="VSDEIH"."STOCK_EQUIPMENT_ID")
    44 - access("SE"."MODEL_ID"="M"."MODEL_ID")
    49 - access("GS"."GAME_WARE_ID"="GW"."GAME_WARE_ID"(+))
    51 - access("EC"."GAMESET_ID"="GS"."GAMESET_ID"(+))
    52 - access("S"."SITE_TYPE_ID"="ST"."SITE_TYPE_ID")
    54 - access("L"."SITE_ID"="S"."SITE_ID")
    56 - access(ROWID=ROWID)
    60 - access("MODEL_ATTRIBUTE_VALUE_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."MODEL_ATTRIBUTE_VALUE_ID" AND
    "EC"."EQUIPMENT_ID"="EAV"."EQUIPMENT_ID")
    filter("EAV"."START_DATE">="EC"."START_DATE" AND ("EAV"."END_DATE" IS NULL AND "EC"."END_DATE">="EAV"."START_DATE" OR
    "EC"."END_DATE" IS NULL OR "EAV"."END_DATE"<="EC"."END_DATE") OR "EC"."START_DATE">="EAV"."START_DATE" AND ("EC"."END_DATE"
    IS NULL AND "EAV"."END_DATE">="EC"."START_DATE" OR "EAV"."END_DATE" IS NULL OR "EC"."END_DATE"<="EAV"."END_DATE"))
    61 - access("EC"."EQUIPMENT_ID"="EC"."EQUIPMENT_ID")
    62 - access("STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID")
    64 - access("EC"."MODEL_ID"="STOCK_EQUIPMENT"."MODEL_ID")
    66 - filter("EC"."END_DATE" IS NULL)
    68 - filter("ES"."EQUIPMENT_STATUS_CODE"='AVA')
    69 - access("EC"."EQUIPMENT_STATUS_ID"="ES"."EQUIPMENT_STATUS_ID")
    71 - filter("EAV"."END_DATE" IS NULL)
    73 - access("EC"."LOCATION_ID"="L"."LOCATION_ID")
    77 - access("STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"=:B1)
    78 - access("STOCK_EQUIPMENT"."STOCK_EQUIPMENT_ID"="STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID")
    filter("STOCK_EQUIPMENT_ATTRIB_VALUE"."STOCK_EQUIPMENT_ID"=:B1)
    5 minutes reduced to 7 seconds.!!
    THE QUESTION.
    Which (and where) query hint do I use to get the FIRST query to use the execution plan "method" of the second -
    IE: To still perform well when a IN-LIST is used instead of EQUALS.
    Technical:
    Oracle 10.2.0.2 EE on Solaris 8, 64 bit.
    Please help.
    Thank you.
    Below is the code of the referenced views for clarity.
    CREATE OR REPLACE FORCE VIEW etrak.v_stocked_equipment_inven_his (stock_equipment_id,
    equipment_id,
    model_id,
    gameset_id,
    gameset_is_active,
    game_ware_id,
    game_ware_is_active,
    equipment_status_code,
    ec_start_date,
    ec_end_date,
    eav_start_date,
    eav_end_date,
    model_attribute_value_id,
    site_id,
    is_store
    AS
    SELECT DISTINCT stock_equipment_id, equipment_id, model_id, gameset_id,
    gameset_is_active, game_ware_id, game_ware_is_active,
    equipment_status_code, ec_start_date, ec_end_date,
    eav_start_date, eav_end_date, model_attribute_value_id,
    site_id, is_store
    FROM (SELECT stock_equipment_id, equipment_id, model_id,
    gameset_id, gameset_is_active, game_ware_id,
    game_ware_is_active, equipment_status_code,
    ec_start_date, ec_end_date, eav_start_date,
    eav_end_date, model_attribute_value_id, site_id,
    is_store
    FROM (SELECT DISTINCT equipment_id, model_id,
    gameset_id, gameset_is_active,
    game_ware_id, game_ware_is_active,
    equipment_status_code,
    model_attribute_value_id,
    ec_start_date, ec_end_date,
    eav_start_date, eav_end_date,
    site_id, is_store
    FROM (SELECT ec.equipment_id,
    ec.model_id,
    gs.gameset_id,
    gs.active_flag
    AS gameset_is_active,
    gw.game_ware_id,
    gw.active_flag
    AS game_ware_is_active,
    es.equipment_status_code,
    ec.start_date
    AS ec_start_date,
    ec.end_date
    AS ec_end_date,
    l.site_id, st.is_store
    FROM equipment_configuration ec,
    equipment_status es,
    LOCATION l,
    site s,
    site_type st,
    gameset gs,
    game_ware gw
    WHERE ec.equipment_status_id =
    es.equipment_status_id
    AND ec.gameset_id = gs.gameset_id(+)
    AND gs.game_ware_id = gw.game_ware_id(+)
    AND ec.location_id =
    l.location_id
    AND l.site_id = s.site_id
    AND s.site_type_id =
    st.site_type_id)
    JOIN
    (SELECT ec.equipment_id,
    model_attribute_value_id,
    eav.start_date
    AS eav_start_date,
    eav.end_date
    AS eav_end_date
    FROM equipment_configuration ec,
    equipment_attribute_value eav
    WHERE ec.equipment_id =
    eav.equipment_id)
    USING (equipment_id)
    WHERE ( eav_start_date >=
    ec_start_date
    AND ( ( eav_end_date IS NULL
    AND ec_end_date >=
    eav_start_date
    OR ec_end_date IS NULL
    OR eav_end_date <=
    ec_end_date
    OR ( ec_start_date >=
    eav_start_date
    AND ( ( ec_end_date IS NULL
    AND eav_end_date >=
    ec_start_date
    OR eav_end_date IS NULL
    OR ec_end_date <=
    eav_end_date
    JOIN
    (SELECT stock_equipment_id, model_id,
    model_attribute_value_id
    FROM stock_equipment JOIN stock_equipment_attrib_value
    USING (stock_equipment_id)
    ) USING (model_id,
    model_attribute_value_id)
    CREATE OR REPLACE FORCE VIEW etrak.v_stock_equipment_mod_man_list (stock_equipment_id,
    stock_equipment_code,
    model_id,
    model_name,
    model_type_id,
    model_type_code,
    model_type_name,
    man_id,
    man_name
    AS
    SELECT se.stock_equipment_id, se.stock_equipment_code, m.model_id,
    m.model_name, mt.model_type_id, mt.model_type_code,
    mt.model_type_name, ma.man_id, ma.man_name
    FROM stock_equipment se, model m, model_type mt, manufacturer ma
    WHERE se.model_id = m.model_id
    AND m.model_type_id = mt.model_type_id
    AND m.man_id = ma.man_id;

    What also makes it difficult to read is the lack of formatting tags ([code][/code] or [pre][/pre]) so that we can actually read the code and execution plans.
    I'm not going to trawl through formatting all that myself just to try and see what the differences are between query 1 and query 2.
    Also bear in mind that when query 2 ran, the data may have been cached and so there is less physical I/O required.
    You don't really want to use any hints to cause re-use of execution plans from 1 query to a different query (like I said, I don't know how different they are). What you want to do is determine what poor SQL coding is making the first query slow and fix it.

  • Performance issue on query. Help needed.

    This is mainly a performance issue. I hope someone can help me on this.
    Basically I have four tables Master (150000 records), Child1 (100000+ records), Child2 (50 million records !), Child 3 (10000+ records)
    (please pardon the aliases).
    Now every record in master has more than one corresponding record in each of the child tables (one to many).
    Also there may not be any record in any or all of the tables for a particular master record.
    Now, I need to fetch the max of last_updated_date for every master record in each of the 3 child tables and then find the maximum of
    the three last_active_dates obtained from the 3 tables.
    eg: for Master ID 100, I need to query Child1 for all the records of Master ID 100 and get the max last_updated_date.
    Same for the other 2 tables and then get the maximum of these three values.
    (I also need to take care of cases where no record may be found in a child table for a Master ID)
    Writing a procedure that uses cursors that fetches the value from each of the child table hits performance
    badly. And thing is I need to find out the last_updated_date for every Master record (all 150000 of them). It'll probably take days to do this.
    SELECT MAX (C1.LAST_UPDATED_DATE)
    ,MAX (C2.LAST_UPDATED_DATE)
    ,MAX (C3.LAST_UPDATED_DATE)
    FROM CHILD1 C1
    ,CHILD2 C2
    ,CHILD3 C3
    WHERE C1.MASTER_ID = 100
    OR C2.MASTER_ID = 100
    OR C3.MASTER_ID = 100
    I tried the above but I got a temp tablespace error. I don't think the query is good enough at all.
    (The OR clause is to take care of no records in any child table. If there's an AND, then the join and hence select will
    fail even if there is no record in one child table but valid values in the other 2 tables).
    Thanks a lot.
    Edited by: user773489 on Dec 16, 2008 11:49 AM

    Not sure I understand the problem. The max you are getting from the above is already the greatest out of the three - that's why we do the UNION ALL.
    Here's sample code without output, maybe this will clear it up:
    with a as (
    select 10 MASTER_ID, to_date('12/15/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 20 MASTER_ID, to_date('12/01/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 30 MASTER_ID, to_date('12/02/2008', 'MM/DD/YYYY') LAST_DTE from dual
    b as (
    select 10 MASTER_ID, to_date('12/14/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 20 MASTER_ID, to_date('12/02/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 40 MASTER_ID, to_date('11/15/2008', 'MM/DD/YYYY') LAST_DTE from dual
    c as (
    select 10 MASTER_ID, to_date('12/07/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 30 MASTER_ID, to_date('11/29/2008', 'MM/DD/YYYY') LAST_DTE from dual UNION ALL
    select 40 MASTER_ID, to_date('12/13/2008', 'MM/DD/YYYY') LAST_DTE from dual
    select MASTER_ID, MAX(LAST_DTE)
    FROM
    (select MASTER_ID, LAST_DTE from a UNION ALL
    select MASTER_ID, LAST_DTE from b UNION ALL
    select MASTER_ID, LAST_DTE from c)
    group by MASTER_ID;
    MASTER_ID              MAX(LAST_DTE)            
    30                     02-DEC-08                
    40                     13-DEC-08                
    20                     02-DEC-08                
    10                     15-DEC-08                
    4 rows selectedEdited by: tk-7381344 on Dec 16, 2008 12:38 PM

  • Error in Query (Pls help)

    Hi friends,
    When i executed one of the queries, i get this error:
    Abort System error in program <b>CL_RSDM_READ_MASTER_DATA and form_sidval_direct</b>
    Diagnosis
    This internal error is a targeted termination since the program has an incorrect status.
    Procedure
    Analyse the situation and inform SAP.
    I have check all my infoobjects and master data...everything is in active but still i dont understand why i get this....
    please suggest how to get rid of this error? its urgent
    Regards
    Balaji

    Hi balaji,
       This can be program error, need to apply support package or correction,
    seems no oss found for form_sidval_direct .....
    perhaps it's sid error, try to analyze and repair the infoprovider where the query created on, use transaction RSRV.
    hope this helps.
    assign points if useful
    Regards,
    Archna

  • Order by problem in my query - plz help me out

    Dear all,
    I have a query like this,
    Select Booking_No, Get_Bl_Number (Booking_No) Bl_No, Depot_Code
    From Booking_Table
    Where Booking_Mode = 'B'
    Order By Depot_Code, Bl_No, Booking_No
    i need the output like NULLs of Bl_No should come first..ie.,
    DEPOT_CODE BL_NO BOOKING_NO
    DEPOT01 BOOKING01
    DEPOT01 BL01 BOOKING02
    DEPOT03 BL04 BOOKING03
    DEPOT04 BOOKING04
    DEPOT05 BL05 BOOKING06
    since am using the function to get the Bl_No, am not getting the NULLs first...kindly help me out
    Thanx and Rgds,
    M Thiyagu

    You can use like this:
    Order By
       Depot_Code,
       Bl_No nulls first ,
       Booking_No

  • Advice / Help needed on how to tackle this mountain...

    First, I've scoured the forums looking for an answer and some clarity, but have come up empty. Any advice or help you can offer will be greatly appreciated...
    So I'm trying to tackle the feat of sorting though thousands of MP3s in several different fodlers, and getting them all stored in one folder, with just the ones I want to keep (estimated to be about 3,000 when all said and done). Having iTunes just automatically copy them as I drag and drop is perfect, but I don't want the program to automatically sort them in hundreds of different folders. Is there a way to not completely turn this folder off, but have it just copy into the root folder?
    Assuming the answer is no, what's the best way for me to approach this? Right now I've turned off the copy feature, have been adding 100 or so songs into a new playlist, editing the tags in iTunes, and copying into my finish root folder. However, I obviously lose my rating when I move the files, and have to update my library by removing all previous files in library, and adding the root folder again.
    A way around this is for me to just not assign a rating to any files until I have my final root folder set for import into iTunes library, but this also raises a conceptual problem: I use other programs for uplaoding songs from CDs and DLing, and have them all sent to an "Unsorted MP3s" folder. I would like to be able to go back to this folder, edit the tags and clean them up, then copy them into the root folder and updating my library without having to remove all and reimport the whole folder, losing all my ratings and playcounts.
    So I guess there's really 2 questions I have;
    First, is there a way to have iTunes just copy the file into a root folder without automatically sorting and creating folders itself?
    If no, what's the best way for me to go about updating, importing, and copying songs into a singular root folder? I realize I could just stay on top of it, and only add a few files at a time individually, but that solution isn't very feasible when I'd like to update and add large numbers at a time.
    I gotta imagine there's something I'm missing here and it's possible. I did have the idea of merging ALL of my MP3s into my root folder first, then delete and edit from iTunes, eventually ending with a perfect library and all files in one folder. However, I'm still posed with the problem of how to add files at a later date without losing my whole library...
    Hopefully I haven't been too confusing, and I'll be sure to offer more clarity if need be. Thanks in advance for all the help!
    -Mike

    Im not a 100% sure on what your trying to do, i think and correct me if im wrong but you want to copy all your songs that are scattered all over the pc into one folder in the root but not have itunes consolidate the files into folders by name etc.
    Im not sure if this is of any help to you but i had songs scattered all over my pc and wanted to put them in a central folder and then share that folder accross multiple user accounts on the one pc (this could be the root if you wish i just chose shared music) if you follow the following link it explained what i did to put all my music in the one place. (I urge caution though as im not 100% certain if this is what you want to do, anyway hope it help)
    http://discussions.apple.com/thread.jspa?threadID=608497&tstart=0

  • PROBLEM WITH HIERARCHICAL QUERY - PLEASE HELP

    I have got three tables :
    CREATE TABLE FIRM
    (FID INTEGER NOT NULL PRIMARY KEY,
    FNAME VARCHAR(40),
    FTYPE VARCHAR(3),
    MASTERID INTEGER );
    CREATE TABLE FACULTY
    (FAID INTEGER NOT NULL PRIMARY KEY,
    FANAME VARCHAR(40),
    FATYPE VARCHAR(3),
    MASTERID INTEGER );
    CREATE TABLE EMPLOYEE
         (EID INTEGER NOT NULL PRIMARY KEY,
    ENAME VARCHAR(20),
    ESURNAME VARCHAR(20),
         EJOB VARCHAR(3),
         MASTERID INTEGER );
    This is a hierarchical tree(or is ment to be, I,m complete rookie ) . Firm can be the root or can be slave to another firm. Faculty can be slave to firm, or to another faculty. Employee can be slave to faculty or to another employee(e.g. boss). This connections are specified by MASTERIDs.
    I need to write a procedure, which parameter would be node ID. It is meant to create a VIEW from this node as if it was a root (view of a subtree).
    I tried CONNECT BY clause but it works only on one table at a time and I have here three tables.
    I completely don,t know how to write it. Please help.

    create view hierarchy as
    select id, master_id, name from table1
    union all
    select id, master_id, name from table2
    union all
    select id, master_id, name from table3
    Then do your connect by query against hierarchy.
    It will not work in 8i (connect by on views not allowed), so you will need to materialize the view.
    Kirill

  • How to make recursive query.Please help

    Dear Experts:
    I want to retrieve all employees located in a department in addition to all other employees located in the child's nodes of this department too.
    Problem Details:
    I have "Employees" table and "Departments" Table
    The structure of Dept Table is:
    ID   primary key
    parent_dept   foreign key(id)
    deptname  varchar2
    deptType varchar2
    The Employee table structure is
    ID primary key
    dept_id foreign key(Department.id)
    empName varchar2Sample data for departments
    ID : 1
    parent_dept : null
    deptname: General Manager office
    deptType : 'GM'
    ID :=2
    parent_dept : 1
    deptname: Information tech.
    deptType : 'DPT'
    ID :=3
    parent_dept : 2
    deptname: Software Development
    deptType : 'SECTION'Sample Data for employees
    ID : 101
    dept_id  :1
    empName  King
    ID : 102
    dept_id  :2
    empName  ALAN
    ID : 103
    dept_id  :2
    empName  SAM
    ID : 104
    dept_id  :3
    empName  JANEI want to create a query that accepts a parameter "p_department_id" and returns All employees on the following conditions
    1- In case the parameter value is null , then retrieve All Employees "king - alan- sam-jane"
    2- In Case the parameter value is 1 , then retrieve all the employees under department id =1 in addition to all the employees located under the children departments.
    in this case it will be "king - alan- sam-jane"
    3- In case parameter value is 2 , then return all the employees under department id =2 in addition to all the employees located under the children departments.
    In this case it will be " alan- sam-jane"
    4- In case parameter value is 3 , then return all the employees under department id =3 in addition to all the employees located under the children departments.
    in this case it will be only "JANE"
    In brief , If I pass any value to the parameter :p_department_id , I want to retrieve all employees located in this department in addition to other employees located in the child's nodes of this department id
    I use oracle database 11g release 2
    Please help me
    Thanks
    Edited by: ta**** on Apr 3, 2013 5:56 PM
    Edited by: ta**** on Apr 3, 2013 5:58 PM

    SQL> variable p_department_id number
    SQL> exec :p_department_id := null
    PL/SQL procedure successfully completed.
    SQL> with employees as (
      2                     select 101 id,1 dept_id,'King' empName from dual union all
      3                     select 102,2,'ALAN' from dual union all
      4                     select 103,2,'SAM' from dual union all
      5                     select 104,3,'JANE' from dual
      6                    ),
      7     departments as (
      8                     select 1 id,null parent_dept,'General Manager office' deptname,'GM' deptType from dual union all
      9                     select 2,1,'Information tech.','DPT' from dual union all
    10                     select 3,2,'Software Development','SECTION' from dual
    11                    )
    12  select  *
    13    from  employees
    14    where dept_id in (
    15                      select  id
    16                        from  departments
    17                        start with (
    18                                       (
    19                                            :p_department_id is null
    20                                        and
    21                                            parent_dept is null
    22                                       )
    23                                    or
    24                                       id = :p_department_id
    25                                   )
    26                        connect by parent_dept = prior id
    27                     )
    28  /
            ID    DEPT_ID EMPN
           101          1 King
           102          2 ALAN
           103          2 SAM
           104          3 JANE
    SQL> exec :p_department_id := 1
    PL/SQL procedure successfully completed.
    SQL> /
            ID    DEPT_ID EMPN
           101          1 King
           102          2 ALAN
           103          2 SAM
           104          3 JANE
    SQL> exec :p_department_id := 2
    PL/SQL procedure successfully completed.
    SQL> /
            ID    DEPT_ID EMPN
           102          2 ALAN
           103          2 SAM
           104          3 JANE
    SQL> exec :p_department_id := 3
    PL/SQL procedure successfully completed.
    SQL> /
            ID    DEPT_ID EMPN
           104          3 JANE
    SQL> SY.

  • SQL Query -- Please Help

    Table1
    QTE_ID     SEQ_NO
    1435177     2
    1435177     5
    1435177     7
    1435177     8
    1435177     12
    1435177     14
    Table2
    QTE_ID     SEQ_NO     CMMT_CURR_AMT
    1435177     1     98500
    1435177     2     98500
    1435177     3     0
    1435177     4     98500
    1435177     5     98500
    1435177     7     98500
    1435177     8     98500
    1435177     11     59300
    1435177     12     59300
    1435177     14     59300
    The result should be
    QTE_ID     SEQ_NO     CMMT_CURR_AMT
    1435177     2     0 (where 0 = cmmt_curr_amt of seq 2 - cmmt_curr_amt of seq 1 from table 2)
    1435177     5     0 (where 0 = cmmt_curr_amt of seq 5 - cmmt_curr_amt of seq 4 from table 2)
    1435177     7     0 (where 0 = cmmt_curr_amt of seq 7 - cmmt_curr_amt of seq 5 from table 2)
    1435177     8     0 (where 0 = cmmt_curr_amt of seq 8 - cmmt_curr_amt of seq 7 from table 2)
    1435177     12     0 (where 0 = cmmt_curr_amt of seq 12 - cmmt_curr_amt of seq 11 from table 2)
    1435177     14     0 (where 0 = cmmt_curr_amt of seq 14 - cmmt_curr_amt of seq 12 from table 2)
    I have to get the difference of cmmt_curr_amt from the table2 from seq 14 to seq 12 for seq14 in table 1.
    Please help me in writing the query.
    Thanks in advance.
    Srinivas

    WITH table1 AS
    (SELECT 1435177 qte_id, 2 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no
    FROM dual
    table2 AS
    SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
    FROM dual
    SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
    FROM
    (SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
    FROM table1 t1, table2 t2
    WHERE t2.qte_id = t1.qte_id (+)
    AND t2.seq_no = t1.seq_no(+)
    ORDER BY 1,2
    WHERE t1_seq_no IS NOT NULL
    ORDER BY 1,2
    QTE_ID T2_SEQ_NO DIFF
    1435177 2 0
    1435177 5 0
    1435177 7 0
    1435177 8 0
    1435177 12 0
    1435177 14 0

Maybe you are looking for

  • Javadoc @return and @returns

    Does anyone know what's the difference between Javadoc @return and @returns? When do we use which tag to document the return type?

  • Increased Installer Size in LabVIEW 8.5

    I have an installer for an application I wrote in LabVIEW 8.5.1 that includes nothing but the application itself and the LabVIEW RTE.  It used to weigh in at ~75 MB, but since I installed LabVIEW 2009 the installer now takes up ~115 MB.  I poked arou

  • How to restrict decimal values from number in OAF

    Hi All, My requirement is, when ever user enter number in text box, if the number having decimal it should throw an exception to enter for only integer values. Appreciate help on this. Regards, Rakesh

  • Mac OS 10.5.5 Bluetooth issue

    I have a 2.4 Ghz MacBook Pro and the built in bluetooth as been screwy since I updated to 10.5.5. I have a wireless mighty mouse and a white apple bluetooth keyboard, the one just prior to the aluminum models. If I touch the numeric keypad on the key

  • Moving clips around in project

    I have ten minutes of clips in a project with a few titles and transitions. I want to move them around to create the flow of my movie, but try as I might, I can't drag a clip anywhere. I've tried everything, option click, alt click, shift click. The