Plz help in tuning this query......

SELECT "LAN","VEF_REF_NO","VF_TYPE_CODE","APPLICANT_TYPE","MANDATORY","OPTIONAL","COMPLETE","DT_COMPLETED","REFIRENO","ROLE","USER_ID","DT_LASTUPDATED","TEMPLATEFIRED"
FROM T_VER_STRATEGY_DETAILS M
WHERE VF_TYPE_CODE =1 AND
APPLICANT_TYPE ='A' AND
DT_LASTUPDATED=
(SELECT MAX(DT_LASTUPDATED)
FROM T_VER_STRATEGY_DETAILS
WHERE LAN = M.LAN AND
VF_TYPE_CODE =1 AND APPLICANT_TYPE ='A')
This seems to be a correlated query.
i tried using combined index on
(VF_TYPE_CODE ,APPLICANT_TYPE ,DT_LASTUPDATED)
and another index on
(LAN,VF_TYPE_CODE ,APPLICANT_TYPE ) but the plan or cost remains unchained.
plz help

[url http://forums.oracle.com/forums/thread.jspa?threadID=501834&tstart=0]When your query takes too long...

Similar Messages

  • Plz help me design this query

    Hi,
    Can you’ll please help me with this query.
    Here is a little bit of background:
    One title can have multiple items associated with it.
    Table: TITLE has the master list of titles. TITLE_ID is the primary key.
    Table: ITEM has the master list of all items. ITEM_ID is the primary. This table also has the TITLE_ID which stores title for this item.
    Table: ITEM_STATUS has fields ITEM_ID and STATUS_ID. This field contains statuses for items. But not all items contained in the table ITEM are in this table.
    I want to find TITLE_ID’s whose all items (all ITEM_ID in table ITEM having same value for TITLE_ID) have a particular status (for example STATUS_ID = 2) in table ITEM_STATUS.
    Let’s say TITLE_ID = 1 has 5 items in table ITEM_ID and only 4 items out of it in table ITEM_STATUS with STATUS_ID = 2, then this TITLE_ID should not come. OR
    Let’s say TITLE_ID = 1 has 5 items in table ITEM_ID and all these 5 items are in table ITEM_STATUS but only 1 has STATUS_ID = 2, then this TITLE_ID should also not come
    In the above case only if all 5 items are contained in table ITEM_STATUS have STATUS_ID = 2 then this TITLE_ID should be reported by the query.
    What should be the query like for this one, I am fairly new to SQL so plz guide me.
    Thank you,
    Raja

    I haven't tested the query below. Try it and let me know for any issues:
    SELECT     DISTINCT t.title_id
         FROM     title t,
                        item i,
                        item_status its
    WHERE     t.title_id = i.title_id
         AND     i.item_id = its.item_id
         AND     NOT EXISTS     (
                                                           SELECT 1
                                                                FROM item_status its1
                                                           WHERE its1.item_id = i.item_id
                                                                AND status_id <> 'YOUR_ITEM_STATUS'
                                                      )

  • Plz help to make this query......very urgent

    I ve two tables <br>
    <br>
    First one is <b>grn_dtl</b> containing following fields     <br> <br> <br>
    <u><b>
    item_code        ent_dt       qty    doc_no </u></b><br>
    11001318        09/09/2003   5    56300501 <br>
    11001318        11/09/2004        9    56300502 <br>
    11001318        12/05/2005       2    56300503 <br>
    11001319        22/06/2004        0    56300504 <br>
    11001320        09/06/2005        0    56300505 <br>
    11001320        11/08/2004        8    56300506 <br>
    11001320        30/05/2005       4    56300507 <br>
    11001320        21/06/2003       1    56300508 <br>
    11001321        25/09/2004       1    56300509 <br>
    11001321        15/07/2004       1    56300510 <br>
    11001321        01/08/2004       2    56300511 <br>
    11001322        02/06/2004       1    56300512 <br>
    11001322        22/06/2004        2    56300513 <br>
    11001323        12/09/2004        1    56300514 <br>
    11001323        08/05/2004        4    56300515 <br>
    11001323        17/08/2004        5    56300516 <br>
    11001323        28/06/2004        2    56300517 <br>
    <br><br>
    second one is <b>item_mst</B> containing following fields     <br>
    <br>
    <u><b>          
    item_code         description         leadtim   kanbandate</u></b><br>
    11001318           aaaaaaaaaaa            15             22/04/2004<br>
    11001319           aaaaaaaaaaa           15             02/12/2004<br>
    11001320           aaaaaaaaaaa           15             14/07/2005<br>
    11001321           aaaaaaaaaaa           15              23/02/2004<br>
    11001322           aaaaaaaaaaa           15             05/10/2004<br>
    11001323           aaaaaaaaaaa           15             17/05/2004<br>
    11001324           aaaaaaaaaaa           15             27/12/2004<br>
    11001325           aaaaaaaaaaa           15             07/08/2004<br>
    <br><br><br><b>
    From the above two tables I want the combine SQL query which will display item_code its description ,kanbandate from item_mst table and will also display the minimum ent_dt of each corresponding item_code alongwith the qty and doc_no.the item_code should not be repeated .<br>
    I want to run the query from sql query analyzer</b><br><br>
    the result should be like this<br><br>
    <b></u>item_code  desc              ent_dt      qty    doc_no</b></u>
    <br>
    11001318       aaaaaaaaaaa        09/09/2003        5        56300501<br>
    11001319       aaaaaaaaaaa        22/06/2004       0        56300504<br>
    11001320       aaaaaaaaaaa        21/06/2003       1        56300508<br>
    11001321       aaaaaaaaaaa        15/07/2004        1       56300510<br>
    11001322       aaaaaaaaaaa        02/06/2004        1        56300513<br>
    11001323       aaaaaaaaaaa        08/05/2004        4       56300515<br>
    <br>
    <br>
    plz help me out ASAP
    null
    Message was edited by:
    aanchal_2008

    can you try this,
    SELECT DISTINCT im.item_code,
    im.descR,
    gd.ent_dt,
    gd.qty,
    gd.doc_no
    FROM item_mst im,
    grn_dtl gd
    WHERE im.item_code = gd.item_code (+)
    AND NOT EXISTS (
    SELECT 'later detail'
    FROM grn_dtl gd2
    WHERE gd2.item_code = gd.item_code
    AND gd2.ent_dt > gd.ent_dt)
    ITEM_CODE DESCR ENT_DT QTY DOC_NO
    11001318 aaaaaaaaaaa 2/12/2005 6 563005
    11001319 aaaaaaaaaaa 6/22/2004 0 563005
    11001320 aaaaaaaaaaa 6/9/2005 0 563005
    11001321 aaaaaaaaaaa 12/5/2005 5 563005
    11001322 aaaaaaaaaaa 6/22/2004 2 563005
    11001323 aaaaaaaaaaa 9/12/2004 1 563005
    11001324 aaaaaa
    11001325 aaaaaa
    8 rows selected

  • Help in Tuning this Query

    Hi,
    I have a query in my proj where the same table is looked up twice in the same query.
    Can anybody suggest in improving the performance of this query?
    select * from table1 a1 where (a1.column1, a1.column2, a1.column3, a1.column4, a1.column5, a1.column6, a1.column7, a1.column8, a1.column9,
    a1.column10) in ( select a2.column1, a2.column2, a2.column3, a2.column4, a2.column5, a2.column6, a2.column7, a2.column8, a2.column9,
    a2.column10 from table1 a2 where column20 = '<condn>')
    The table1 used here is same in outer query as well as the sub query. this is a example of what we use here, and the table1 contains 30 million rows. Though, creating index with 10 columns can be a option, we already have a unique index with 11 columns(which includes 10 from this query) and will that be helpful in anyway? or the same existing index can be forced?
    Thanks a lot for ur time

    Depending on the selectivity of column20 I am not sure Index is the best way to go. It might perform better with two full scans and a hash-join.
    Anyway, I do prefer the syntax:
    select /*+ leading(a2) */ a1.*
    from table1 a1, table1 a2
    where a2.column20 = '<condn>'
    and a1.column1 = a2.column1
    and a1.column2 = a2.column2
    and  a1.column3 = a2.column3
    and  a1.column4 = a2.column4
    and  a1.column5 = a2.column5
    and  a1.column6 = a2.column6
    and  a1.column7 = a2.column7
    and  a1.column8 = a2.column8
    and  a1.column9 = a2.column9
    and  a1.column10 = a2.column10;I've added a leading hint to tell oracle that the start table is a2. Might be useless.
    Ensure your stats are up to date. You might need histograms here if your column20 is skewed.
    Hope this helps,
    François
    Edited by: Francois Berger on Oct 24, 2008 1:47 AM

  • Help on tuning this query

    Hi all i have this query:
    SELECT VTA.CO_VENDEDOR
    ,VTA.NB_VENDEDOR
    ,VTA.CO_CLASE_CLIENTE
    ,VTA.DE_CLASE_CLIENTE
    ,VTA.CO_CLIENTE
    ,VTA.NB_CLIENTE
    ,VTA.MN_VENDIDO
    ,NVL(DEV.MN_DEVUELTO,0) MN_DEVUELTO
    ,VTA.MN_VENDIDO - NVL(DEV.MN_DEVUELTO,0) MN_NETO_VENDIDO
    ,NVL(COB.MN_COBRADO,0) MN_COBRADO
    ,NVL(COB.MN_DESCUENTO,0) MN_DESCUENTO
    ,NVL(COB.MN_COBRADO,0) + NVL(COB.MN_DESCUENTO,0) MN_COBRADO_MAS_DESCUENTO
    FROM (SELECT FCL.CTV_CO_CLASE_ORGANIZACION CO_CLASE_CLIENTE
    ,FCL.CTV_DE_CLASE_ORGANIZACION DE_CLASE_CLIENTE
    ,FCL.CO_ORGANIZACION CO_CLIENTE
    ,FCL.ORG_NB_CLIENTE NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR CO_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND NB_VENDEDOR
    ,SUM((CA_PRODUCTO * (PR_PRODUCTO - NVL(PR_DESCUENTO_PRODUCTO,0))) * (1 - NVL(PC_DESCUENTO,0))) MN_VENDIDO
    FROM S04_FACTURA_CLIENTE_TOTAL_R FCL
    ,S04_FACTURA_CLIENTE_PRD_TOT FPR
         ,(SELECT FCP.FAC_ID_FACTURA
    ,SUM(DDC.MN_DEBITO_CREDITO) /
    SUM(FCP.CA_PRODUCTO * (FCP.PR_PRODUCTO - NVL(FCP.PR_DESCUENTO_PRODUCTO,0))) PC_DESCUENTO
         FROM S04_DOCUMENTO_DEBITO_CREDITO_R DDC
    ,S04_FACTURA_CLIENTE_PRD_TOT FCP
         WHERE DDC.ID_DOCUMENTO_REFERENCIA = FCP.FAC_ID_FACTURA
    AND DDC.TDC_IN_DEBITO_CREDITO = 'C'
    GROUP BY FCP.FAC_ID_FACTURA) DCT
    WHERE FCL.ID_REGISTRO = FPR.FAC_ID_FACTURA
    AND DCT.FAC_ID_FACTURA (+) = FPR.FAC_ID_FACTURA
    AND FCL.FE_EMISION BETWEEN to_date('01112009','ddmmyyyy') AND to_date('29112009','ddmmyyyy')
    AND FCL.ORG_ID_CLIENTE = NVL(NULL,FCL.ORG_ID_CLIENTE)
    AND FCL.PER_ID_VENDEDOR = NVL(7647771,FCL.PER_ID_VENDEDOR)
                   AND FCL.CTV_CO_ESTADO_DOCUMENTO = 'EM'
    AND FCL.UBG_ID_UBICACION_CLIENTE in (SELECT ID_REGISTRO
    FROM S00_UBICACION_GEOGRAFICA
    START WITH ID_REGISTRO = nvl(NULL, FCL.UBG_ID_UBICACION_CLIENTE)
    CONNECT BY PRIOR ID_REGISTRO = UBG_ID_UBICACION_PADRE)
    GROUP BY FCL.CTV_CO_CLASE_ORGANIZACION
    ,FCL.CTV_DE_CLASE_ORGANIZACION
    ,FCL.CO_ORGANIZACION
    ,FCL.ORG_NB_CLIENTE
    ,PER_CO_IDENTIFICACION_VENDEDOR
    ,PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    PER_NB_PRIMER_APELLIDO_VEND) VTA
    ,(SELECT NDC .CTV_CO_CLASE_ORGANIZACION CO_CLASE_CLIENTE
    ,NDC.CTV_DE_CLASE_ORGANIZACION DE_CLASE_CLIENTE
    ,NDC.CO_CLIENTE
    ,NDC.ORG_NB_CLIENTE NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR CO_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND NB_VENDEDOR
    ,SUM(CA_PRODUCTO * (PR_PRODUCTO - NVL(PR_DESCUENTO_PRODUCTO,0))) MN_DEVUELTO
    FROM S06_NOTA_DEBITO_CREDITO_TOT_R NDC
         ,S06_DETALLE_NOTA_DEB_CRED_TOT DND
    ,S04_FACTURA_CLIENTE_TOTAL_R FCL
         WHERE NDC.ID_REGISTRO = DND.NDC_ID_NOTA_DEBITO_CREDITO
    AND NDC.CTV_CO_TIPO_DOCUMENTO = SK00_BUSCAR.F_VCT('CO_TIPO_DOCUMENTO_NOTA_CREDITO_FISCAL')
    AND NDC.CTV_CO_ESTADO_DOCUMENTO = SK00_BUSCAR.F_VCT('CO_ESTADO_DOCUMENTO_EMITIDO')
         AND NDC.FE_EMISION BETWEEN to_date('01112009','ddmmyyyy') AND to_date('29112009','ddmmyyyy')
         AND (NDC.CTV_CO_MOTIVO_NOTA = SK00_BUSCAR.F_VCT('CO_MOTIVO_NOE_DEVOLUCION')
         OR NDC.CTV_CO_MOTIVO_NOTA = SK00_BUSCAR.F_VCT('CO_MOTIVO_AJUSTE_PRECIO_NCD'))
    AND NDC.ORG_ID_CLIENTE = NVL(NULL,NDC.ORG_ID_CLIENTE)
    AND FCL.ID_REGISTRO = NDC.FAC_ID_FACTURA
                             AND FCL.CTV_CO_ESTADO_DOCUMENTO = 'EM'
    AND FCL.UBG_ID_UBICACION_CLIENTE in (SELECT ID_REGISTRO
    FROM S00_UBICACION_GEOGRAFICA
    START WITH ID_REGISTRO = nvl(NULL, FCL.UBG_ID_UBICACION_CLIENTE)
    CONNECT BY PRIOR ID_REGISTRO = UBG_ID_UBICACION_PADRE)
    GROUP BY NDC.CTV_CO_CLASE_ORGANIZACION
    ,NDC.CTV_DE_CLASE_ORGANIZACION
    ,NDC.CO_CLIENTE
    ,NDC.ORG_NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND) DEV
    ,(SELECT RCD .CTV_CO_CLASE_ORGANIZACION CO_CLASE_CLIENTE
    ,RCD.CTV_DE_CLASE_ORGANIZACION DE_CLASE_CLIENTE
    ,RCD.CO_ORGANIZACION CO_CLIENTE
    ,RCD.ORG_NB_DISTRIBUIDOR NB_CLIENTE
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR CO_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND NB_VENDEDOR
    ,SUM(RCD.MN_DESCUENTO) MN_DESCUENTO
    ,SUM(DECODE(SIGN(RCO.MN_COBRADO_ANTES - IVA.MN_IVA)
    ,-1
    ,RCD.MN_ABONO - ABS(RCO.MN_COBRADO_ANTES - IVA.MN_IVA)
    ,RCD.MN_ABONO)) MN_COBRADO
    FROM S06_RECIBO_COBRO_DOC_TOTAL_R RCD
    ,S04_FACTURA_CLIENTE_TOTAL_R FCL
    ,(SELECT ID_DOCUMENTO_REFERENCIA FAC_ID_FACTURA
    ,NVL(SUM(MN_DEBITO_CREDITO),0) MN_IVA
    FROM S04_DOCUMENTO_DEBITO_CREDITO_R
    WHERE TDC_CO_TIPO_DEBITO_CREDITO = SK00_BUSCAR.F_VCT('CO_TIPO_DEBITO_IVA')
    GROUP BY ID_DOCUMENTO_REFERENCIA) IVA
    ,(SELECT ID_REFERENCIA FAC_ID_FACTURA
    ,NVL(SUM(MN_ABONO),0) MN_COBRADO_ANTES
    FROM S06_RECIBO_COBRO_DOC_TOTAL_R
    WHERE FE_EMISION < to_date('01112009','ddmmyyyy')
    GROUP BY ID_REFERENCIA) RCO
         WHERE RCD.CTV_CO_ESTADO_DOCUMENTO = SK00_BUSCAR.F_VCT('CO_ESTADO_DOCUMENTO_EMITIDO')
         AND RCD.FE_EMISION BETWEEN to_date('01112009','ddmmyyyy') AND to_date('29112009','ddmmyyyy')
    AND RCD.ORG_ID_ORGANIZACION = NVL(NULL,RCD.ORG_ID_ORGANIZACION)
    AND FCL.CTV_CO_ESTADO_DOCUMENTO = 'EM'
                             AND FCL.ID_REGISTRO = RCD.ID_REFERENCIA
    AND FCL.UBG_ID_UBICACION_CLIENTE in (SELECT ID_REGISTRO
    FROM S00_UBICACION_GEOGRAFICA
    START WITH ID_REGISTRO = nvl(NULL, FCL.UBG_ID_UBICACION_CLIENTE)
    CONNECT BY PRIOR ID_REGISTRO = UBG_ID_UBICACION_PADRE)
    AND IVA.FAC_ID_FACTURA (+) = FCL.ID_REGISTRO
    AND RCO.FAC_ID_FACTURA (+) = FCL.ID_REGISTRO
    GROUP BY RCD.CTV_CO_CLASE_ORGANIZACION
    ,RCD.CTV_DE_CLASE_ORGANIZACION
    ,RCD.CO_ORGANIZACION
    ,RCD.ORG_NB_DISTRIBUIDOR
    ,FCL.PER_CO_IDENTIFICACION_VENDEDOR
    ,FCL.PER_NB_PRIMER_NOMBRE_VENDEDOR||' '||
    FCL.PER_NB_PRIMER_APELLIDO_VEND) COB
    WHERE VTA.CO_CLIENTE = DEV.CO_CLIENTE (+)
    AND VTA.CO_VENDEDOR = DEV.CO_VENDEDOR (+)
    AND VTA.CO_CLIENTE = COB.CO_CLIENTE (+)
    AND VTA.CO_VENDEDOR = COB.CO_VENDEDOR (+)
    ORDER BY VTA.NB_VENDEDOR
    ,VTA.CO_CLIENTE
    Is there a way i can influence the join method on this query ...?
    It's an XE DB.
    Regards, Luis ...!

    THIS IS THE PLAN:
    SQL> /
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=79006 Card=1 Bytes
    =253)
    1 0 SORT (ORDER BY) (Cost=79006 Card=1 Bytes=253)
    2 1 HASH JOIN (OUTER) (Cost=79005 Card=1 Bytes=253)
    3 2 HASH JOIN (OUTER) (Cost=78538 Card=1 Bytes=211)
    4 3 VIEW (Cost=78478 Card=1 Bytes=182)
    5 4 HASH (GROUP BY) (Cost=78478 Card=1 Bytes=232)
    6 5 FILTER
    7 6 HASH JOIN (OUTER) (Cost=78469 Card=1 Bytes=232
    8 7 TABLE ACCESS (BY INDEX ROWID) OF 'T04_FACTUR
    A_PRODUCTO' (TABLE) (Cost=2 Card=1 Bytes=46)
    9 8 NESTED LOOPS (Cost=25 Card=1 Bytes=213)
    10 9 VIEW OF 'V04_FACTURA_CLIENTE_TOTAL_R' (V
    IEW) (Cost=23 Card=1 Bytes=167)
    11 10 NESTED LOOPS (Cost=23 Card=1 Bytes=284
    12 11 NESTED LOOPS (OUTER) (Cost=23 Card=1
    Bytes=278)
    13 12 HASH JOIN (SEMI) (Cost=23 Card=1 B
    ytes=272)
    14 13 NESTED LOOPS (Cost=17 Card=1 Byt
    es=259)
    15 14 NESTED LOOPS (Cost=16 Card=1 B
    ytes=218)
    16 15 NESTED LOOPS (OUTER) (Cost=1
    6 Card=1 Bytes=212)
    17 16 NESTED LOOPS (Cost=15 Card
    =1 Bytes=179)
    18 17 NESTED LOOPS (Cost=15 Ca
    rd=1 Bytes=173)
    19 18 NESTED LOOPS (OUTER) (
    Cost=14 Card=1 Bytes=162)
    20 19 NESTED LOOPS (OUTER)
    (Cost=14 Card=1 Bytes=156)
    21 20 NESTED LOOPS (OUTE
    R) (Cost=14 Card=1 Bytes=150)
    22 21 NESTED LOOPS (OU
    TER) (Cost=14 Card=1 Bytes=144)
    23 22 NESTED LOOPS (
    Cost=14 Card=1 Bytes=105)
    24 23 SORT (UNIQUE
    ) (Cost=2 Card=1 Bytes=13)
    25 24 TABLE ACCE
    SS (FULL) OF 'T00_GRUPO_DATO_USUARIO_ACTIVO' (TABLE (TEMP))
    (Cost=2 Card=1 Bytes=13)
    26 23 TABLE ACCESS
    (BY INDEX ROWID) OF 'T04_FACTURA' (TABLE) (Cost=11 Card=1 B
    ytes=92)
    27 26 INDEX (RAN
    GE SCAN) OF 'I04_FAC_FE_EMISION' (INDEX) (Cost=10 Card=2)
    28 22 TABLE ACCESS (
    BY INDEX ROWID) OF 'T03_EMPRESA_SUCURSAL' (TABLE) (Cost=0 Ca
    rd=1 Bytes=39)
    29 28 INDEX (RANGE
    SCAN) OF 'I03_EMS_EMP' (INDEX) (Cost=0 Card=1)
    30 21 INDEX (UNIQUE SC
    AN) OF 'PK_PRY' (INDEX (UNIQUE)) (Cost=0 Card=1 Bytes=6)
    31 20 INDEX (UNIQUE SCAN
    ) OF 'PK_CAJ' (INDEX (UNIQUE)) (Cost=0 Card=1 Bytes=6)
    32 19 INDEX (UNIQUE SCAN)
    OF 'PK_PEC' (INDEX (UNIQUE)) (Cost=0 Card=1 Bytes=6)
    33 18 TABLE ACCESS (BY INDEX
    ROWID) OF 'T00_CONTENIDO_TABLA_VIRTUAL' (TABLE) (Cost=1 Car
    d=1 Bytes=11)
    34 33 INDEX (UNIQUE SCAN)
    OF 'PK_CTV' (INDEX (UNIQUE)) (Cost=0 Card=1)
    SORRY EXPLAIN OUTPUT TRUNCATED DUE TO SPACE RESTRICION .....
    Any help would be greatly appreciated.
    I believe there must be a way to influence on the tha costly HASH JOIN operation
    SQL> SPOOL OFF

  • Plz help me with this query

    i need to get each manager name, his department name and for each year that is for 81,82,83,84 count of employee's under that manager from emp and dept tables .
    thanks in advance
    select distinct deptno, TO_CHAR (HIREDATE, 'YY'), count(*) from emp group by TO_CHAR(HIREDATE, 'YY'), DEPTNO ORDER BY TO_CHAR(HIREDATE, 'YY'), DEPTNO;
    the above query returns me count of employees ,year and deptno
    SELECT DISTINCT E2.ENAME , E1.ENAME, E1.DEPTNO, E1.MGR, E1.EMPNO, E1.SAL, D.DNAME, D.LOC FROM EMP E1, EMP E2, DEPT D WHERE E1.MGR = E2.EMPNO AND E1.DEPTNO = D.DEPTNO ORDER BY E1.DEPTNO;
    this query returned me manager names and employees under them
    Message was edited by:
    user450660

    At that point you're not too far off, you have most of what you need. In general, any time you see the use of DISTINCT it's a sign that either your query or your data model isn't designed quite right.
    SELECT m.ename,
           d.dname,
           TO_CHAR (e.hiredate, 'YY') AS hire_year,
           COUNT(*) AS emp_count
      FROM emp e, emp m, dept d
    WHERE e.mgr = m.empno
       AND m.deptno = d.deptno
    GROUP BY
           m.ename,
           d.dname,
           TO_CHAR (e.hiredate, 'YY');

  • Plz help me in this query for the tree

    hi All
    I want to bulid tree that start with for example
    schema name "scott"
    then table "dept,emp
    then ename in table emp
    root scott
    parent dept
    child emp_name
    please help me in the query ?

    user222 wrote:
    any help my dearsIf you can draw one simple tree example. Then it will be easy to create query. Because i am confuse about the output. Just draw one example of your desired output tree. Then it will help to find solution.
    And while writing query or any example so use the 6 digit before and after your query or example to keep the formatting in orignal format. Otherwise it becomes hard to read.
    For more information see FAQ on right corner for page.
    -Ammad                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • solved need help in tuning this Query

    hi frs,
    i have created a query like this
    pls help
    Regards
    Rajesh
    Message was edited by:
    Rajesh.mani
    Message was edited by:
    Rajesh.mani

    Code and explain plan should be between [pre] and [/pre] or [code] and [/code] tags like this.
    [pre]Code[/pre]An now explain plan
    [code]Execution plan
    [/code]
    Cheers
    Sarma.

  • Please help me tuning this query...

    Hi all,
    Can any body suggest some changes (synthatic) so that it can improve its performance... taking too much time...
    This is a query used in oracle report...
    SELECT  distinct cc.seg1,cc.seg2,cc.seg3,cc.seg4,cc.seg5,cc.seg6,cc.seg7,cc.seg8,cc.code_combination_id code_comb_id,
             r.flex_validation_rule_name cv_rule,gl.currency_code currency1,                                          
             (NVL (gjl.accounted_dr, 0) - NVL (gjl.accounted_cr, 0)) trans_amount,
             gjh.doc_sequence_value doc_num,
             gjs.user_je_source_name je_source, gjc.user_je_category_name je_category,
             fu.user_name last_updated_by,(NVL (gb.begin_balance_dr, 0)
                   - NVL (gb.begin_balance_cr, 0))
                   + (NVL (gb.period_net_dr_beq, 0)
                   - NVL (gb.period_net_cr_beq, 0)) balance,
             gjh.last_update_date last_updated_date,gjl.effective_date
        FROM gl_code_combinations cc,
             fnd_flex_vdation_rules_vl r,
             fnd_flex_validation_rule_lines l,
             gl_je_headers gjh,
             gl_je_lines gjl,
             gl_balances gb,
             fnd_user fu,
             gl_je_categories gjc,
             gl_je_sources gjs,
             gl_ledgers gl
         WHERE cc.enabled_flag = 'Y'
         AND NVL (cc.end_date_active, SYSDATE + 1) > SYSDATE
         AND cc.chart_of_accounts_id = :p_chart_of_accounts_id
         AND r.id_flex_num = cc.chart_of_accounts_id
         AND r.id_flex_code = 'GL#'
         AND r.application_id = 101
         AND gjs.je_source_name=gjh.je_source
         AND gjc.je_category_name=gjh.je_category
         AND l.application_id = r.application_id
         AND gb.code_combination_id=cc.code_combination_id
         AND gjh.period_name=gb.period_name
         AND r.enabled_flag = 'Y'
         AND NVL (r.end_date_active, SYSDATE + 1) > SYSDATE
         AND l.id_flex_code = r.id_flex_code
         AND l.id_flex_num = r.id_flex_num
         AND l.flex_validation_rule_name = r.flex_validation_rule_name
         AND l.include_exclude_indicator = 'E'
         AND gjl.code_combination_id = gb.code_combination_id
         AND gjh.je_header_id = gjl.je_header_id
         AND gjh.status = 'P'
         AND gl.ledger_id=gjh.ledger_id
         and gl.ledger_id=:p_ledger_id
         AND gjh.last_updated_by = fu.user_id
         and  (gjh.last_update_date,gjl.last_update_date)=(
                SELECT MAX (a.last_update_date) ,MAX(b.last_update_date)
                  FROM gl_je_headers a, gl_je_lines b
                 WHERE b.code_combination_id = cc.code_combination_id
                   AND a.je_header_id = b.je_header_id
                   AND a.status = 'P'
                   AND ROWNUM = 1)
         and (NVL (gjl.accounted_dr, 0) - NVL (gjl.accounted_cr, 0))=(select (NVL (accounted_dr, 0) - NVL (accounted_cr, 0)) from gl_je_lines
           where  je_header_id=gjh.je_header_id and code_combination_id=cc.code_combination_id and period_name=gjh.period_name and
           last_update_date=gjh.last_update_date and rownum=1)
        and  (NVL (gb.begin_balance_dr, 0)
                   - NVL (gb.begin_balance_cr, 0))
                   + (NVL (gb.period_net_dr_beq, 0)
                   - NVL (gb.period_net_cr_beq, 0))=(select max((NVL (begin_balance_dr, 0)
                   - NVL (begin_balance_cr, 0))
                   + (NVL (period_net_dr_beq, 0)
                   - NVL (period_net_cr_beq, 0))) from gl_balances where code_combination_id=cc.code_combination_id
                   and period_name=gb.period_name)  
           and gjl.description=(select description from gl_je_lines where  code_combination_id=cc.code_combination_id and
                                  je_header_id=gjh.je_header_id and period_name=gb.period_name and rownum=1)                    
         AND cc.seg1 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 1, 3),
                                      cc.seg1
                             AND NVL (SUBSTR (l.concatenated_segments_high, 1, 3),
                                      cc.seg1
         AND cc.seg2 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 5, 4),
                                      cc.seg2
                             AND NVL (SUBSTR (l.concatenated_segments_high, 5, 4),
                                      cc.seg2
         AND cc.seg3 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 10, 4),
                                      cc.segt3
                             AND NVL (SUBSTR (l.concatenated_segments_high, 10, 4),
                                      cc.seg3
         AND cc.seg4 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 15, 3),
                                      cc.seg4
                             AND NVL (SUBSTR (l.concatenated_segments_high, 15, 3),
                                      cc.seg4
         AND cc.seg5 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 19, 6),
                                      cc.seg5
                             AND NVL (SUBSTR (l.concatenated_segments_high, 19, 6),
                                      cc.seg5
         AND cc.seg6 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 26, 4),
                                      cc.segment6
                             AND NVL (SUBSTR (l.concatenated_segments_high, 26, 4),
                                      cc.seg6
         AND cc.seg7 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 31, 6),
                                      cc.seg7
                             AND NVL (SUBSTR (l.concatenated_segments_high, 31, 6),
                                      cc.seg7
         AND cc.seg8 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 38, 6),
                                      cc.seg8
                             AND NVL (SUBSTR (l.concatenated_segments_high, 38, 6),
                                      cc.seg8)Thanks for help
    asp

    Dear all,
    the folliwing is explain plan for above query...
    <ExplainPlan>
    - <PlanElement object_ID="0" id="0" operation="SELECT STATEMENT" optimizer="ALL_ROWS" cost="1,417" cardinality="1" bytes="477" cpu_cost="263,995,086" io_cost="1,385" time="18">
    - <PlanElements>
    - <PlanElement object_ID="0" id="1" operation="HASH" option="UNIQUE" cost="1,417" cardinality="1" bytes="477" cpu_cost="263,995,086" io_cost="1,385" time="18">
    - <PlanElements>
    - <PlanElement object_ID="0" id="2" operation="FILTER" filter_predicates="("GJH"."LAST_UPDATE_DATE","GJL"."LAST_UPDATE_DATE")= (SELECT MAX("A"."LAST_UPDATE_DATE"),MAX("B"."LAST_UPDATE_DATE") FROM "GL"."GL_JE_LINES" "B","GL"."GL_JE_HEADERS" "A" WHERE ROWNUM=1 AND "A"."JE_HEADER_ID"="B"."JE_HEADER_ID" AND "A"."STATUS"='P' AND "B"."CODE_COMBINATION_ID"=:B1) AND NVL("GJL"."ACCOUNTED_DR",0)-NVL("GJL"."ACCOUNTED_CR",0)= (SELECT NVL("ACCOUNTED_DR",0)-NVL("ACCOUNTED_CR",0) FROM "GL"."GL_JE_LINES" "GL_JE_LINES" WHERE ROWNUM=1 AND "PERIOD_NAME"=:B2 AND "CODE_COMBINATION_ID"=:B3 AND "JE_HEADER_ID"=:B4 AND "LAST_UPDATE_DATE"=:B5) AND NVL("GB"."BEGIN_BALANCE_DR",0)-NVL("GB"."BEGIN_BALANCE_CR",0)+(NVL("GB"."PERIOD_NET_DR_BEQ",0)-NVL("GB"."PERIOD_NET_CR_BEQ",0))= (SELECT MAX(NVL("BEGIN_BALANCE_DR",0)-NVL("BEGIN_BALANCE_CR",0)+(NVL("PERIOD_NET_DR_BEQ",0)-NVL("PERIOD_NET_CR_BEQ",0))) FROM "GL"."GL_BALANCES" "GL_BALANCES" WHERE "PERIOD_NAME"=:B6 AND "CODE_COMBINATION_ID"=:B7)">
    - <PlanElements>
    - <PlanElement object_ID="0" id="3" operation="NESTED LOOPS" cost="1,262" cardinality="1" bytes="477" cpu_cost="254,376,045" io_cost="1,231" time="16">
    - <PlanElements>
    - <PlanElement object_ID="0" id="4" operation="NESTED LOOPS" cost="1,261" cardinality="1" bytes="464" cpu_cost="254,366,853" io_cost="1,230" time="16">
    - <PlanElements>
    - <PlanElement object_ID="0" id="5" operation="NESTED LOOPS" cost="1,260" cardinality="1" bytes="433" cpu_cost="254,357,622" io_cost="1,229" time="16">
    - <PlanElements>
    - <PlanElement object_ID="0" id="6" operation="NESTED LOOPS" cost="1,259" cardinality="1" bytes="402" cpu_cost="254,348,331" io_cost="1,228" time="16">
    - <PlanElements>
    - <PlanElement object_ID="0" id="7" operation="NESTED LOOPS" cost="1,258" cardinality="1" bytes="350" cpu_cost="254,337,522" io_cost="1,227" time="16">
    - <PlanElements>
    - <PlanElement object_ID="0" id="8" operation="NESTED LOOPS" cost="1,239" cardinality="1" bytes="273" cpu_cost="254,166,811" io_cost="1,208" time="15">
    - <PlanElements>
    - <PlanElement object_ID="0" id="9" operation="HASH JOIN" cost="1,184" cardinality="1" bytes="248" cpu_cost="253,727,112" io_cost="1,153" access_predicates=""B"."ID_FLEX_NUM"="CC"."CHART_OF_ACCOUNTS_ID"" filter_predicates=""CC"."SEGMENT1">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",1,3),"CC"."SEGMENT1") AND "CC"."SEGMENT1"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",1,3),"CC"."SEGMENT1") AND "CC"."SEGMENT2">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",5,4),"CC"."SEGMENT2") AND "CC"."SEGMENT2"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",5,4),"CC"."SEGMENT2") AND "CC"."SEGMENT3">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",10,4),"CC"."SEGMENT3") AND "CC"."SEGMENT3"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",10,4),"CC"."SEGMENT3") AND "CC"."SEGMENT4">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",15,3),"CC"."SEGMENT4") AND "CC"."SEGMENT4"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",15,3),"CC"."SEGMENT4") AND "CC"."SEGMENT5">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",19,6),"CC"."SEGMENT5") AND "CC"."SEGMENT5"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",19,6),"CC"."SEGMENT5") AND "CC"."SEGMENT6">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",26,4),"CC"."SEGMENT6") AND "CC"."SEGMENT6"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",26,4),"CC"."SEGMENT6") AND "CC"."SEGMENT7">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",31,6),"CC"."SEGMENT7") AND "CC"."SEGMENT7"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",31,6),"CC"."SEGMENT7") AND "CC"."SEGMENT8">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",38,6),"CC"."SEGMENT8") AND "CC"."SEGMENT8"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",38,6),"CC"."SEGMENT8")" time="15">
    - <PlanElements>
    - <PlanElement object_ID="1" id="10" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULE_LINES" object_type="TABLE" object_instance="3" cost="3" cardinality="1" bytes="119" cpu_cost="49,909" io_cost="3" filter_predicates=""L"."INCLUDE_EXCLUDE_INDICATOR"='E'" time="1">
    - <PlanElements>
    - <PlanElement object_ID="0" id="11" operation="NESTED LOOPS" cost="6" cardinality="1" bytes="189" cpu_cost="75,588" io_cost="6" time="1">
    - <PlanElements>
    - <PlanElement object_ID="0" id="12" operation="NESTED LOOPS" cost="3" cardinality="1" bytes="70" cpu_cost="25,679" io_cost="3" time="1">
    - <PlanElements>
    - <PlanElement object_ID="0" id="13" operation="NESTED LOOPS" cost="3" cardinality="1" bytes="39" cpu_cost="23,779" io_cost="3" time="1">
    - <PlanElements>
    - <PlanElement object_ID="2" id="14" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_LEDGERS" object_type="TABLE" object_instance="10" cost="1" cardinality="1" bytes="8" cpu_cost="8,541" io_cost="1" time="1">
    - <PlanElements>
      <PlanElement object_ID="3" id="15" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_LEDGERS_U2" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,050" io_cost="0" access_predicates=""GL"."LEDGER_ID"=TO_NUMBER(:P_LEDGER_ID)" time="1" />
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="4" id="16" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULES" object_type="TABLE" object_instance="19" cost="2" cardinality="1" bytes="31" cpu_cost="15,238" io_cost="2" filter_predicates=""B"."ENABLED_FLAG"='Y' AND NVL("B"."END_DATE_ACTIVE",SYSDATE@!+1)>SYSDATE@!" time="1">
    - <PlanElements>
      <PlanElement object_ID="5" id="17" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULES_U1" object_type="INDEX (UNIQUE)" search_columns="3" cost="1" cardinality="1" cpu_cost="7,321" io_cost="1" access_predicates=""B"."APPLICATION_ID"=101 AND "B"."ID_FLEX_CODE"='GL#' AND "B"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID)" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      <PlanElement object_ID="6" id="18" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VDATION_RULES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="5" cost="0" cardinality="1" bytes="31" cpu_cost="1,900" io_cost="0" access_predicates=""T"."APPLICATION_ID"=101 AND "T"."ID_FLEX_CODE"='GL#' AND "T"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND "B"."FLEX_VALIDATION_RULE_NAME"="T"."FLEX_VALIDATION_RULE_NAME" AND "T"."LANGUAGE"=USERENV('LANG')" time="1" />
      </PlanElements>
      </PlanElement>
      <PlanElement object_ID="7" id="19" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VAL_RULE_LINES_N1" object_type="INDEX" search_columns="4" cost="1" cardinality="41" cpu_cost="16,371" io_cost="1" access_predicates=""L"."APPLICATION_ID"=101 AND "L"."ID_FLEX_CODE"='GL#' AND "L"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND "L"."FLEX_VALIDATION_RULE_NAME"="B"."FLEX_VALIDATION_RULE_NAME"" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      <PlanElement object_ID="8" id="20" operation="TABLE ACCESS" option="FULL" optimizer="ANALYZED" object_owner="GL" object_name="GL_CODE_COMBINATIONS" object_type="TABLE" object_instance="1" cost="1,177" cardinality="1,088" bytes="64,192" cpu_cost="249,419,570" io_cost="1,147" filter_predicates=""CC"."ENABLED_FLAG"='Y' AND "CC"."CHART_OF_ACCOUNTS_ID"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND NVL("CC"."END_DATE_ACTIVE",SYSDATE@!+1)>SYSDATE@!" time="15" />
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="9" id="21" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES" object_type="TABLE" object_instance="6" cost="55" cardinality="52" bytes="1,300" cpu_cost="439,699" io_cost="55" time="1">
    - <PlanElements>
      <PlanElement object_ID="10" id="22" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES_N1" object_type="INDEX" search_columns="1" cost="2" cardinality="52" cpu_cost="25,693" io_cost="2" access_predicates=""GB"."CODE_COMBINATION_ID"="CC"."CODE_COMBINATION_ID"" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="11" id="23" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="5" cost="19" cardinality="40" bytes="3,080" cpu_cost="170,710" io_cost="19" time="1">
    - <PlanElements>
      <PlanElement object_ID="12" id="24" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="1" cost="2" cardinality="49" cpu_cost="24,693" io_cost="2" access_predicates=""GJL"."CODE_COMBINATION_ID"="GB"."CODE_COMBINATION_ID"" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="13" id="25" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS" object_type="TABLE" object_instance="4" cost="1" cardinality="1" bytes="52" cpu_cost="10,809" io_cost="1" filter_predicates=""GJH"."STATUS"='P' AND "GJH"."LEDGER_ID"=TO_NUMBER(:P_LEDGER_ID) AND "GJH"."PERIOD_NAME"="GB"."PERIOD_NAME"" time="1">
    - <PlanElements>
    - <PlanElement object_ID="14" id="26" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,950" io_cost="0" access_predicates=""GJH"."JE_HEADER_ID"="GJL"."JE_HEADER_ID"" filter_predicates=""GJL"."DESCRIPTION"= (SELECT "DESCRIPTION" FROM "GL"."GL_JE_LINES" "GL_JE_LINES" WHERE ROWNUM=1 AND "PERIOD_NAME"=:B1 AND "CODE_COMBINATION_ID"=:B2 AND "JE_HEADER_ID"=:B3)" time="1">
    - <PlanElements>
    - <PlanElement object_ID="0" id="27" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
    - <PlanElements>
    - <PlanElement object_ID="11" id="28" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="15" cost="5" cardinality="1" bytes="62" cpu_cost="39,168" io_cost="5" filter_predicates=""JE_HEADER_ID"=:B1" time="1">
    - <PlanElements>
      <PlanElement object_ID="12" id="29" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="4" cpu_cost="22,364" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="15" id="30" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_SOURCES_TL" object_type="TABLE" object_instance="16" cost="1" cardinality="2" bytes="62" cpu_cost="9,291" io_cost="1" time="1">
    - <PlanElements>
      <PlanElement object_ID="16" id="31" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_SOURCES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="2" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""JE_SOURCE_NAME"="GJH"."JE_SOURCE" AND "LANGUAGE"=USERENV('LANG')" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="17" id="32" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_CATEGORIES_TL" object_type="TABLE" object_instance="17" cost="1" cardinality="2" bytes="62" cpu_cost="9,231" io_cost="1" time="1">
    - <PlanElements>
      <PlanElement object_ID="18" id="33" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_CATEGORIES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="2" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""JE_CATEGORY_NAME"="GJH"."JE_CATEGORY" AND "LANGUAGE"=USERENV('LANG')" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="19" id="34" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_USER" object_type="TABLE" object_instance="7" cost="1" cardinality="1" bytes="13" cpu_cost="9,191" io_cost="1" time="1">
    - <PlanElements>
      <PlanElement object_ID="20" id="35" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_USER_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""GJH"."LAST_UPDATED_BY"="FU"."USER_ID"" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="0" id="36" operation="SORT" option="AGGREGATE" cardinality="1" bytes="33">
    - <PlanElements>
    - <PlanElement object_ID="0" id="37" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
    - <PlanElements>
    - <PlanElement object_ID="0" id="38" operation="NESTED LOOPS" cost="69" cardinality="49" bytes="1,617" cpu_cost="624,699" io_cost="69" time="1">
    - <PlanElements>
    - <PlanElement object_ID="11" id="39" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="12" cost="20" cardinality="49" bytes="882" cpu_cost="164,029" io_cost="20" time="1">
    - <PlanElements>
      <PlanElement object_ID="12" id="40" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="1" cost="3" cardinality="49" cpu_cost="30,964" io_cost="3" access_predicates=""B"."CODE_COMBINATION_ID"=:B1" time="1" />
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="13" id="41" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS" object_type="TABLE" object_instance="11" cost="1" cardinality="1" bytes="15" cpu_cost="9,401" io_cost="1" filter_predicates=""A"."STATUS"='P'" time="1">
    - <PlanElements>
      <PlanElement object_ID="14" id="42" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""A"."JE_HEADER_ID"="B"."JE_HEADER_ID"" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="0" id="43" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
    - <PlanElements>
    - <PlanElement object_ID="11" id="44" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="13" cost="5" cardinality="1" bytes="33" cpu_cost="39,068" io_cost="5" filter_predicates=""JE_HEADER_ID"=:B1 AND "LAST_UPDATE_DATE"=:B2" time="1">
    - <PlanElements>
      <PlanElement object_ID="12" id="45" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="4" cpu_cost="22,364" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
    - <PlanElement object_ID="0" id="46" operation="SORT" option="AGGREGATE" cardinality="1" bytes="25">
    - <PlanElements>
    - <PlanElement object_ID="9" id="47" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES" object_type="TABLE" object_instance="14" cost="6" cardinality="1" bytes="25" cpu_cost="45,399" io_cost="6" time="1">
    - <PlanElements>
      <PlanElement object_ID="10" id="48" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="2" cpu_cost="21,964" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      </PlanElements>
      </PlanElement>
      </ExplainPlan>Sorry this xml generated...
    Regards
    asp

  • Plz help in building this query .

    dear gurus i have problem i have two tables namely purchases
    product_id,invoice_no,invoice_date,purchase_rate,quantity
    and
    sales
    product_id,invoice_no,invoice_date,sales_rate,quantity
    i have to select sales.product_id,sales.quantity*sales.sales_rate and average of (purchase_rate*purchae.quantity) i.e average purchase price of particular product i.e. group by product_id and purchase price in between particular dates but i m unable to find any good soloution. any help plz
    null

    I'm not sure I understand your grouping goal, but...
    select sales.product_id,
    sales.quantity*sales.sales_rate sttl
    pur.avgp
    from sales
    (select avg ( purchase_rate *
    quantity) avgp,
    product_id
    from purchases
    group by product_id) pur
    where sales.product_id = pur.product_id
    and sales.invoice_date between
    '04-jun-1999' and '05-may-2001';
    If you need more complex grouping, you can add it.

  • Plz help me rectify this query

    Hi,
    I am trying to use a OR condition in NOT IN clause, is the SQL statement correct way:
    select name from master_list where ((id not in (select id from deleted_list)) OR (id not in (select id from inactive_list)))
    I there are two tables which contain ids which should be in not in clause.
    Thanks,
    Raja

    Hi,
    Whenever you post fomatted text on this site (and code should always be formatted), type these 6 characters:
    &#123;code&#125;
    (small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.
    What is the problem?
    Are you getting an error message?
    Why not post the error message?
    Are you getting the wrong results?
    Post some sample data, and the results you want to get from that data.
    NOT IN will never be TRUE if the sub-query includes any NULL rows. I can't tell if that's possible with your tables or not..

  • Plz help me debug this query

    query
    create table third_party
    (customer_id varchar2,
    third_party varchar2,
    foreign key (third_party) references account(type),
    foreign key (customer_id) references customer(customer_id),
    primary key(customer_id,third_party));
    Error
    ORA-00906: missing left parenthesis

    Please see this ..these are done
    create table account
    (account_no number primary key,
    type varchar2(10),
    balance number(20) );
    create table registered_account
    ( account_no number primary key,
    customer_id varchar2(10),
    foreign key (account_no) references account(account_no),
    foreign key (customer_id) references registered_users(customer_id) );
    create table registered_users
    (customer_id varchar2(20) primary key,
    user_id varchar2(10),
    login_password varchar2(10),
    foreign key (customer_id) references customer(customer_id));
    create table transaction
    (transaction_id number primary key,
    to_account number,
    from_account number,
    tr_date date,
    amount number,
    customer_id varchar2(10),
    foreign key (to_account) references account(account_no),
    foreign key (from_account) references account(account_no),
    foreign key (customer_id) references customer(customer_id));
    create table has
    (customer_id,
    account_no,
    foreign key (customer_id) references customer(customer_id),
    foreign key (account_no) references account(account_no),
    primary key(customer_id,account_no));
    create table customer
    (customer_id varchar2(20)primary key,
    name varchar2(15),
    address varchar2(50),
    city varchar2(20),pin number(6),
    dob varchar2(10),ph_no number(10));
    The following is nt working
    create table third_party
    (customer_id varchar2(20),
    third_party varchar2(10),
    foreign key (third_party) references account(type),
    foreign key (customer_id) references customer(customer_id),
    primary key(customer_id,third_party));

  • Need Help in tuning this query

    select CO_PROFILE.CO_NO AS "UEN No.",
    CO_PROFILE.CO_NAME AS "Entity Name",
    DECODE(CO_PROFILE.CO_TYPE,'A1','PUBLIC COMPANY LIMITED BY SHARES',
    'A3','COMPANY LIMITED BY GUARANTEE',
    'A4','UNLIMITED PUBLIC COMPANY',
    'B1','LIMITED PRIVATE COMPANY',
    'B2','LIMITED EXEMPT PRIVATE COMPANY',
    'B3','UNLIMITED PRIVATE COMPANY',
    'B4','UNLIMITED EXEMPT PRIVATE COMPANY',
    'F1','FOREIGN COMPANY REGISTERED IN SINGAPORE') AS "Entity Type",
    M_STATUS.STATUS_DESC AS "Entity Status",
    PAYMENT_DETAIL.SERVICE_CODE AS "Service Code",
    PAYMENT_DETAIL.PAYMENT_CODE AS "Payment Code",
    CO_TRANS_MAST.CO_TRANS_ID AS "Transaction Type",
    M_PAYMENT_CODE.PAYMENT_DESC AS "Payment Description",
    M_PAYMENT_CODE.REVENUE_CODE AS "Revenue Account",
    CO_TRANS_MAST.NUM AS "Number Of Transactions",
    PAY_NEW.UNIT_AMT AS "Revenue Amount1",
    PAY_NEW.FILING_AMT AS "Revenue Amount2",
    PAYMENT_DETAIL.UNIT_FEE AS "Unit Cost"
    from CO_PROFILE,
    M_STATUS,
    PAYMENT_DETAIL,
    CO_TRANS_MASTER,
    (Select COUNT(CO_NO) AS "NUM",CO_TRANS_ID,CO_NO
    from CO_TRANS_MASTER
    group by CO_NO,CO_TRANS_ID
    )CO_TRANS_MAST,
    (Select Sum(UNIT_FEE) AS UNIT_AMT,
      SUM(FILING_FEE) AS FILING_AMT,
       TRANS_NO AS TRANS_NO
      from
      PAYMENT_DETAIL
      group by
      TRANS_NO)
    PAY_NEW,
    M_PAYMENT_CODE
    where rownum=1
    and CO_PROFILE.CO_STATUS=M_STATUS.STATUS_CODE
    and M_STATUS.TRANS_ID='COMP'
    and CO_TRANS_MASTER.CO_TRANS_ID=CO_TRANS_MAST.CO_TRANS_ID
    and CO_TRANS_MASTER.CO_NO=CO_TRANS_MAST.CO_NO
    and PAYMENT_DETAIL.TRANS_NO=CO_TRANS_MASTER.CO_TRANS_NO
    and PAY_NEW.TRANS_NO=PAYMENT_DETAIL.TRANS_NO
    and CO_TRANS_MAST.CO_NO= CO_PROFILE.CO_NO
    and M_PAYMENT_CODE.PAYMENT_CODE=PAYMENT_DETAIL.PAYMENT_CODE

    Something seems wrong to me with the logical structure of the select.
    1) You only get 1 row of output
    but you
    2) build sums for each trans_no
    3) You join the table co_trans_master but at the same time you count over that one. Might be ok to do so, but it seems to be double the work.
    Suggestion.
    a) Build a select that joins the payment detail table. Then group this select and build the sums.
    b) Add the count for the number of transactions to the select clause instead of and extra inline view in the from clause. Maybe as an analytical function if possible.

  • Accent insensitive Search - plz help me correcting this query

    Hello,
    I just realized that with that query, if I search for "Montreal" (without the accent), I have all the following results, which is what I want
    SELECT
    "ID","TIT"
    from   "REGDOSSIERS" "RDO"
           where
             TRANSLATE(UPPER("TIT"),'ÀÂÉÈÊÎÔÛÙÜ','AAEEEIOUUU')
             like upper(nvl(replace('%' || "P1_REPORT_SEARCH || '%',' ','%'),"TIT"))
    RESULTS
    TIT
    Annuaires Lovell (Montréal et banlieue)
    Juridiction royale de Montréal. Dossiers, 1677-1769
    Montreal Witness, 1845-1938
    {code}
    But how to change it so when I look for: "Montréal" (with the accent) , I have also the same results? Right now, with Montréal, I have nothing
    thanks,
    Roseline
    Edited by: Roseline on 2009-10-01 18:58
    Edited by: Roseline on Oct 1, 2009 7:34 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    If you are on Oracle 10g you can use regexp expressions to do the search.
    Example
    with testdata as (select 'Montreal' txt from dual
                      union all select 'Montréal' txt from dual
                      union all select 'Montreâl' txt from dual
                      union all select 'Montreaux' txt from dual)
    /* end of test data creation */
    select txt from testdata
    where regexp_like (txt, 'Montr[[=e=]]al');
    txt
    Montreal
    Montréal[[=e=]] would be an equivalence class for the letter "e" and includes also searches for é, è, ê etc.
    The best solution mainly depends how your search string is build.
    If you just want to sort, then the nlssort function would be useful.
    Mentioning Nlssort I remembered there is a much better way to implement Accent insensitive search. You just need to set your NLS_SORT parameter correctly. Either to BINARY_AI (the AI means accent and case insensitiv) or add _AI to your nls langage.
    example
    ALTER SESSION SET NLS_COMP=LINGUISTIC;
    alter session set nls_sort = 'FRENCH';
    with testdata as (select 'Montreal' txt from dual
                      union all select 'Montréal' txt from dual
                      union all select 'Montreâl' txt from dual
                      union all select 'Montreaux' txt from dual)
    /* end of test data creation */
    select txt from testdata
    where txt = 'MONTREAL';
    no rows selects
    /* now change the nls sorting */
    alter session set nls_sort = 'FRENCH_AI';
    with testdata as (select 'Montreal' txt from dual
                      union all select 'Montréal' txt from dual
                      union all select 'Montreâl' txt from dual
                      union all select 'Montreaux' txt from dual)
    /* end of test data creation */
    select txt from testdata
    where txt = 'MONTREAL';
    txt
    Montreal
    Montréal
    MontreâlEdited by: Sven W. on Oct 2, 2009 8:34 AM
    Edited by: Sven W. on Oct 2, 2009 10:22 AM - corrected misleading regexp example.

  • Plz help to make this query......

    I ve two table <br>
    <br>
    First one is grn_dtl containing following fields     <br> <br> <br>
    <u><b>
    item_code        ent_dt       qty    doc_no </u></b><br>
    11001318        09/09/2003   5    56300501 <br>
    11001318        11/09/2004        9    56300502 <br>
    11001318        12/05/2005       2    56300503 <br>
    11001319        22/06/2004        0    56300504 <br>
    11001320        09/06/2005        0    56300505 <br>
    11001320        11/08/2004        8    56300506 <br>
    11001320        30/05/2005       4    56300507 <br>
    11001320        21/06/2003       1    56300508 <br>
    11001321        25/09/2004       1    56300509 <br>
    11001321        15/07/2004       1    56300510 <br>
    11001321        01/08/2004       2    56300511 <br>
    11001322        02/06/2004       1    56300512 <br>
    11001322        22/06/2004        2    56300513 <br>
    11001323        12/09/2004        1    56300514 <br>
    11001323        08/05/2004        4    56300515 <br>
    11001323        17/08/2004        5    56300516 <br>
    11001323        28/06/2004        2    56300517 <br>
    <br><br>
    second one is <b>item_mst</B> containing following fields     <br>
    <br>
    <u><b>          
    item_code         description         leadtime   kanbandate</u></b><br>
    11001318           AIR FILTERS            15             22/04/2004<br>
    11001319     AIR FILTER KIT DSK      15     02/12/2004
    11001320     AIR FILTER FOR 3.0     15     14/07/2005
    11001321     AIR FILTER NA 21323130      15     23/02/2004
    11001322     AMPERE METER DC-0-50     15     05/10/2004
    11001323     ACTUATER KIT     15     17/05/2004
    11001324     ACTUATOR HOSE      15     27/12/2004
    11001325     AIR GUN MEDIUM     15     07/08/2004
    from the above two tables I want the query which will display item_code its description ,kanbandate from item_mst table and will also display the minimum ent_dt of each corresponding

    select m.item_code,m.description,m.kanbandate,min(d.end_dt)
    from item_mst m,grn_dtl d
    where m.item_code = d.item_code
    group by m.item_code,m.description,m.kanbandate

Maybe you are looking for

  • Out of the blue, my computer stops working and refuses to power up. Can anyone help?

    So I am posting this on a Thursday night. Monday morning and night, my computer was working fine. Come Tuesday, however, and my computer won't turn on. I don't think much of it; I shrug it off and head to school. Come back from school, and the comput

  • Deadlock in TopLink when using JMS listener on WebLogic

    I am experiencing a deadlock in TopLink 10.1.3 on WebLogic 9 in code that previously worked on TopLink 9.0.4 with WebLogic 8.1. As such, I'm not sure if it's due to the TopLink change, the WebLogic change or both. Anyway, we have a JMS listener (note

  • HT4628 iMac looses wifi connection

    My iMac (OS 10.8.5) looses wifi connection every once in a while. I go to Network Diagnostics, press all those Continue buttons, at some point it sais "Your Internet connection appears to be working correctly" and the Internet connection is being res

  • How to edit song info

    I have always been able to edit song information in I-tunes.  Today, I downloaded a song, and I cannot edit the genre.  I right click on the name of the song, select "get info," and get the page, but the page is sort of faded.  I cannot edit anything

  • Displaying image from binary code

    I am converting a image file(jpg) into a binary file and sending it. In the receiving side i get the binary file and want to display the image in the applet or store the image in a file. while trying to do this i am not able to read the image from th