How to set this query, please suggest me.

Under query returns the rows 50 million but taking 6 minutes to complete:

Select / * + full (udf) full (udm) full (ul) full (d) full (hw) PARALLEL (udf 16) PARALLEL (udm 16) PARALLEL (ul 16) PARALLEL (d 16) PARALLEL (hw 16) * /.

SEPARATE d.dmdunit, d.loc,

-case when d.seasonprofile! = ' ' then rtrim (d.seasonprofile, '_SO')

When d.seasonprofile = ' ' then the UDM. UPPER_ITEM_LEVEL | '_' || UL. UPPER_LOC_LEVEL

end as seasonprofile,

-case when EXTRACTED (D.HISTSTART YEAR) > = NVL (EXTRACT (YEAR FROM HW. STARTDATE), 1970)

then

-case when EXTRACTED (D.HISTSTART YEAR) < = (select EXTRACT (YEAR FROM SYSDATE) double)-2 then (select EXTRACT (YEAR FROM SYSDATE) double)-2

another end extract (D.HISTSTART YEAR)

When EXTRACTED (D.HISTSTART YEAR) < NVL (EXTRACT (YEAR FROM HW. (STARTDATE), (select EXTRACT (YEAR FROM SYSDATE) double)) then

-case when EXTRACT (YEAR FROM HW. STARTDATE) < = (select EXTRACT (YEAR FROM SYSDATE) double)-2

then (select EXTRACT (YEAR FROM SYSDATE) double)-2

on the other EXTRACT (YEAR FROM HW. STARTDATE); ultimately as startyear

d.DMDUNIT | '_' || d.LOC as profilename, UDM. UPPER_ITEM_LEVEL, UL. UPPER_LOC_LEVEL, d.model, 0 MOVINGEVENTAPPLIED

OF STSC.udt_dfuview udf, udm stsc.udt_dmdunit, ul STSC.udt_loc, STSC.dfu d, STSC.histwide hw

where udf.dmdunit = udm.dmdunit

AND udf.loc = ul.loc

AND udf.dmdunit = d.dmdunit

AND udf.dmdgroup = d.dmdgroup

AND udf.loc = d.loc

AND udf.jda_dfuview_level (111, 112, 114)

AND udf.calcmodel = 1

AND udf.dmdunit = hw.dmdunit (+)

AND udf.dmdgroup = hw.dmdgroup (+)

AND udf.loc = hw.loc (+)

AND udf.attach_seasonality_ind! = 2

AND (d.seasonprofile LIKE the UDM. UPPER_ITEM_LEVEL | '_' || UL. UPPER_LOC_LEVEL | '%' OR d.seasonprofile;

Explain the Plan of the above query:

-----------------------------------------------------------------------------------------------------------------------------------

| ID | Operation | Name | Lines | Bytes | TempSpc | Cost (% CPU). Time |    TQ | IN-OUT | PQ Distrib.

-----------------------------------------------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT |             |   235K |    86 M |       |   250K (1) | 00:58:25 |        |      |            |

|   1.  QUICK DOUBLE |             |     1.       |       |     2 (0) | 00:00:01 |        |      |            |

|   2.   QUICK DOUBLE |             |     1.       |       |     2 (0) | 00:00:01 |        |      |            |

|   3.    QUICK DOUBLE |             |     1.       |       |     2 (0) | 00:00:01 |        |      |            |

|   4.     QUICK DOUBLE |             |     1.       |       |     2 (0) | 00:00:01 |        |      |            |

|   5.      QUICK DOUBLE |             |     1.       |       |     2 (0) | 00:00:01 |        |      |            |

|   6.  COORDINATOR OF PX |             |       |       |       |            |          |        |      |            |

|   7.   PX SEND QC (RANDOM). : TQ10006 |   235K |    86 M |       |   250K (1) | 00:58:25 |  Q1, 06 | P > S | QC (RAND) |

|   8.    UNIQUE HASH |             |   235K |    86 M |    27G |   250K (1) | 00:58:25 |  Q1, 06 | SVCP |            |

|   9.     RECEIVE PX |             |   235K |    86 M |       |   250K (1) | 00:58:25 |  Q1, 06 | SVCP |            |

|  10.      PX SEND HASH | : TQ10005 |   235K |    86 M |       |   250K (1) | 00:58:25 |  Q1, 05 | P > P | HASH |

|  11.       UNIQUE HASH |             |   235K |    86 M |    27G |   250K (1) | 00:58:25 |  Q1, 05 | SVCP |            |

| * 12 |        HASH JOIN |             |    72 M |    26G |       |   250K (1) | 00:58:22 |  Q1, 05 | SVCP |            |

|  13.         RECEIVE PX |             |   183K |  4825K |       |   127 (0) | 00:00:02 |  Q1, 05 | SVCP |            |

|  14.          PX SEND BROADCAST | : TQ10000 |   183K |  4825K |       |   127 (0) | 00:00:02 |  Q1 00 | P > P | BROADCAST |

|  15.           ITERATOR BLOCK PX |             |   183K |  4825K |       |   127 (0) | 00:00:02 |  Q1 00 | ISSUE |            |

|  16.            TABLE ACCESS FULL | UDT_DMDUNIT |   183K |  4825K |       |   127 (0) | 00:00:02 |  Q1 00 | SVCP |            |

| * 17.         HASH JOIN |             |    75 M |    25G |       |   249K (1) | 00:58:20 |  Q1, 05 | SVCP |            |

|  18.          RECEIVE PX |             | 78266 |  1834K |       |    22 (0) | 00:00:01 |  Q1, 05 | SVCP |            |

|  19.           PX SEND BROADCAST | : TQ10001 | 78266 |  1834K |       |    22 (0) | 00:00:01 |  Q1, 01 | P > P | BROADCAST |

|  20.            ITERATOR BLOCK PX |             | 78266 |  1834K |       |    22 (0) | 00:00:01 |  Q1, 01 | ISSUE |            |

|  21.             TABLE ACCESS FULL | UDT_LOC | 78266 |  1834K |       |    22 (0) | 00:00:01 |  Q1, 01 | SVCP |            |

| * 22.          HASH JOIN |             |    75 M |    23G |       |   249K (1) | 00:58:19 |  Q1, 05 | SVCP |            |

| * 23.           OUTER HASH JOIN |             |    76 M |  5227M |       |   200K (1) | 00:46:48 |  Q1, 05 | SVCP |            |

|  24.            RECEIVE PX |             |    76 M |  2686M |       |   159K (1) | 00:37:10 |  Q1, 05 | SVCP |            |

|  25.             PX SEND HASH | : TQ10002 |    76 M |  2686M |       |   159K (1) | 00:37:10 |  Q1, 02 | P > P | HASH |

|  26.              ITERATOR BLOCK PX |             |    76 M |  2686M |       |   159K (1) | 00:37:10 |  Q1, 02 | ISSUE |            |

| * 27.               TABLE ACCESS FULL | UDT_DFUVIEW |    76 M |  2686M |       |   159K (1) | 00:37:10 |  Q1, 02 | SVCP |            |

|  28.            RECEIVE PX |             |    83 M |  2786M |       | 41225 (1) | 00:09:38 |  Q1, 05 | SVCP |            |

|  29.             PX SEND HASH | : TQ10003 |    83 M |  2786M |       | 41225 (1) | 00:09:38 |  Q1, 03 | P > P | HASH |

|  30.              ITERATOR BLOCK PX |             |    83 M |  2786M |       | 41225 (1) | 00:09:38 |  Q1, 03 | ISSUE |            |

|  31.               TABLE ACCESS FULL | HISTWIDE |    83 M |  2786M |       | 41225 (1) | 00:09:38 |  Q1, 03 | SVCP |            |

|  32.           RECEIVE PX |             |    91 M |    22G |       | 49254 (1) | 00:11:30 |  Q1, 05 | SVCP |            |

|  33.            PX SEND HASH | : TQ10004 |    91 M |    22G |       | 49254 (1) | 00:11:30 |  Q1, 04 | P > P | HASH |

|  34.             ITERATOR BLOCK PX |             |    91 M |    22G |       | 49254 (1) | 00:11:30 |  Q1, 04 | ISSUE |            |

|  35.              TABLE ACCESS FULL | DFU |    91 M |    22G |       | 49254 (1) | 00:11:30 |  Q1, 04 | SVCP |            |

-----------------------------------------------------------------------------------------------------------------------------------

Information of predicates (identified by the operation identity card):

---------------------------------------------------

12 - access("UDF".") DMDUNIT "=" UDM ". ("' DMDUNIT")

filter ("D". "" SEASONPROFILE "AS"UDM ". "' UPPER_ITEM_LEVEL ' | " _'||" « « « UL ». » UPPER_LOC_LEVEL "| " % "OU « D ». » SEASONPROFILE"="

')

17 - access("UDF".") LOC '=' UL '. ("" LOC ")

22 - access("UDF".") DMDUNIT "=" D ". "" DMDUNIT "AND"UDF ". "" DMDGROUP "=" D ". "" DMDGROUP "AND"UDF ". "" LOC "=" D ". ("" LOC ")

23 - access("UDF".") DMDUNIT "=" HW ". "DMDUNIT" (+) AND "UDF". " "" DMDGROUP "=" HW ". "DMDGROUP" (+) AND "UDF". " "' LOC '=' HW '. "LOC" (+)) "

27 - filter("UDF".") CALCMODEL «= 1 AND ('UDF'.» JDA_DFUVIEW_LEVEL '= 111 OR 'UDF'." JDA_DFUVIEW_LEVEL "= 112 OR"

"UDF". ""(=114) AND "UDF" JDA_DFUVIEW_LEVEL '. "" (ATTACH_SEASONALITY_IND"<>2)

Tables do not contain. folders:

-----------------------------------------

SELECT COUNT (*) STSC.udt_dfuview; - 85898925

SELECT COUNT (*) FROM stsc.udt_dmdunit; - 170688

SELECT COUNT (*) STSC.udt_loc; - 79593

SELECT COUNT (*) STSC.histwide; - 55129967

SELECT COUNT (*) STSC.dfu; - 85909083

Thank you, the problem is resolved.

Now it takes half the time. Thanks for your suggestion.

Tags: Database

Similar Questions

  • in the past I have installed the cd into my itunes to mp3, then I transferred to my sandisk mp3 player, now I don't remember how to do this again, please help, what do I forget?

    in the past I have installed the cd into my itunes to mp3, then I transferred to my sandisk mp3 player and now I don't remember how to do this again, please help, what I forget

    Select Edit > Preferences > General (if necessary, press ctrl-B to activate the iTunes menu bar), click import settings..., then select MP3 encoder from the first drop-down and choose the setting of the quality required in the second dropdown.  This then becomes the default format for imported CD media.

  • My iPhone 5 s a problem that the accusation itself decreases without using the phone, I changed the battery it is always the same and I put it in airplane mode it's always the same problem how to solve this help please?

    problem iPhone 5s load is reduced to

    My iPhone 5 s a problem that the accusation itself decreases without using the phone, I changed the battery it is always the same and I put it in airplane mode it's always the same problem how to solve this help please?

    Please help me anyone

  • Browsing databases of Virtual Center failed: could not connect to server NFC, can any body help me how to solve this problem please

    Browsing databases of Virtual Center failed: could not connect to server NFC, can any body help me how to solve this problem please

    Hi Mallik7, please try the following steps, you must succeed to solve the problem.

    To connect a client to vCenter directly to the ESX host error-free work.

    Files/etc/vmware/config the ESX host contain the lines:

    ------------------------------------

    authd.soapServer = 'TRUE '.

    prefvmx.consolidateDeleteNFSLocks = "TRUE" authd.proxy.vpxa - nfc = "vmware - vpxa:vpxa - nfc.

    Authd.proxy.vpxa - nfcssl = ' vmware - vpxa:vpxa - nfcssl.

    ------------------------------------

    This problem occurs when a carriage return is missing from/etc/vmware/config. To resolve this issue, go to edit/etc/vmware/config:

    1 make a backup of this file from the path - / etc/vmware/config, by running the following command:

    CP/etc/vmware/config/var/tmp /.

    2. edit/etc/vmware/config so that there is a return transport after the line:

    prefvmx.consolidateDeleteNFSLocks = 'TRUE '.

    While he reads the following:

    ---------------------------------------------

    authd.soapServer = 'TRUE '.

    prefvmx.consolidateDeleteNFSLocks = 'TRUE '.

    Authd.proxy.vpxa - nfc = "vmware - vpxa:vpxa - nfc.

    Authd.proxy.vpxa - nfcssl = ' vmware - vpxa:vpxa - nfcssl.

    ---------------------------------------------

    3. restart the management agent spend.

    Note: Make sure that you are not in your environment name resolution problems.

  • No idea how to write this query

    Hi, My Data is as below

    DocNum doc_date type of amount
    1154 15 November 11 232501.5 invoice
    200206 4 November 11 - 243672.64 credit memo
    Note flow 111 5 November 555.22 11

    Output must be

    DocNum doc_date amount Type AmountDR AmountCR
    1154 232501.5 15 November 11 Bill 232501.5
    Note credit 200206 4 November 11 - 243672.64 - 243672.64
    Note flow 111 5 November 555.22 11 555.22

    If the amount is > 0, then it must be displayed in the value of the amount to be AmountDR
    If amount < 0 then it must be displayed in the value of the sum amount CR



    Can help how to write this query
    with sample_table as (
                          select 1154 Docnum,date '2011-11-15' doc_date,232501.5 Amount,'Invoice' type from dual union all
                          select 200206,date '2011-11-04',-243672.64,'Credit Memo' from dual union all
                          select 111,date '2011-11-05',555.22,'Debit Memo' from dual
                         )
    select  Docnum,
            doc_date,
            Amount,
            type,
            case
              when Amount >= 0 then Amount
            end AmountDR,
            case
              when Amount < 0 then Amount
            end AmountCR
      from  sample_table
    /
    
        DOCNUM DOC_DATE      AMOUNT TYPE          AMOUNTDR   AMOUNTCR
    ---------- --------- ---------- ----------- ---------- ----------
          1154 15-NOV-11   232501.5 Invoice       232501.5
        200206 04-NOV-11 -243672.64 Credit Memo            -243672.64
           111 05-NOV-11     555.22 Debit Memo      555.22
    
    SQL> 
    

    SY.

  • How to optimize this query?

    Hello

    I have a query like this:

    Merge into the table st1

    using (select * from (select pk, value, diff_value, m_date, row_number () over (PARTITION pk ORDER BY diff_value) rnk)

    from (select distinct / * + Full (t1) full (t2) * / t1.pk, t2.m_date)

    , Case when (t1.m_date = t2.m_date) then "CORRESPONDENCE".

    When (t2.m_date BETWEEN t1.m_date-1 and t1.m_date + 1) then ' MATCHED WITH +/-1gg.

    When (t2.m_date BETWEEN t1.m_date-2 and t1.m_date + 2) then "MATCHED WITH +/-2 days.

    else "

    end value_match

    Case when (t1.m_date = t2.m_date) then 0

    Where (t2.m_date BETWEEN t1.m_date + 1 and t1.m_date - 1) then 1

    Where (t2.m_date BETWEEN t1.m_date + 1 and t1.m_date - 1) then 2

    else "

    end diff_value

    of table t2, t1 table

    where t1.value is null

    and t1.id = t2.id)

    where value_match is not null)

    where rnk = 1) s

    on (st1.pk = s.pk)

    WHEN MATCHED THEN

    Update set st1.value = s.value_match, st1.diff_value = s.diff_value, st1.up_date = s.m_date

    where st1.value is null.

    Explain the plan:

    EXPLAIN_PLAN1.jpg

    Table1 a record 3Million and table 2 has 1 million records.

    I used gather stats before you run this query and 'Full' trick, even in this case, he is running for 45 minutes.

    Please suggest the best solution to optimize this query.

    Thanks in advance.

    Remove the tips.

    No need for the separate.

    Get the diff by ceil (abs(t2.m_date-t1.m_date)) and the filter for that where value_diff<>

    Assing the statement ".. MATCHED" lately in the update clause.

    Maybe give exactly to your needs with a small example may be the query may be getting more simplified or not what you want it to do.

  • How to write this query?

    Hi people,

    I need to get a query in which a set of records, I get ONLY those which previous registry has a field with a value to this topic. Other values, the field can contain are not necessary.

    I know that sounds easy but... I can't get it.

    So, for Oracle 10 g 2... Here's my query:

    SELECT a.person_id, a.person_status, a.message_id, a.order_id

    OF t_HR one

    WHERE a.person_status = "rejected".

    AND a.id >

    (SELECT max (b.id)

    OF t_HR b

    WHERE b.person_id = a.person_id

    and b.order_id = a.order_id

    AND b.person_status! "revised =".

    B.ID AND < a.id)

    ORDER BY desc a.id

    Let me explain:

    1 - HR table is a table of people. These people has serveral STATUS.

    2 - ID is a sequential (each www.voyages-sncf.com has a different identification number).

    3 - the application must get THAT all people "rejected".

    4. - However, (subquery) I need ONLY those that previous register (the second register) holds a status of "OK". If the person holds a "revised" status he's not, he should be the next register (the third)

    5.-L' ORDER ID DESC, so is the first register must have a STATUS = "rejected" and the second a 'OK '.  IF the second register = "revised", then the third register must be 'OK '. And I need this query.

    HOW DO?

    My problem: the subquery gives you previous register of the same guy, but... it does not give you the value of the State, I need, which is 'OK '.

    I tried to add to the subquery...

    SELECT max (b.id)

    OF mod_human_resource b

    WHERE b.person_id = a.person_id

    and b.order_id = a.order_id

    AND b.person_status = 'OK '.

    AND b.id < a.id

    ... but if I have 5 records of that person, the first is "rejected", the second is "accepted", the third is 'new' and the fourth is 'OK'... the subquery gives you the 4th register and which is not correct for me, it must be only the second one (prior to the first State registry).

    I need to be a query, because I need to use it on a MERGER for a DWH.

    If there is another way (function, or even a procedure) to make the MERGER rather than with a request, which would be ok too. I am poor DWH knowledge.

    Thanks in advance.

    Hello

    So, you need to know if a line is the 'first' line, and you should also know what is the 'next' status, (even the 'first' and 'next' are already defined).  This sounds like a job for analytical functions.  ROW_NUMBER can tell you if a line is first or not, and LEAD can tell you what a value on the next row.

    Since you post CREATE TABLE and INSERT statements for your own table, I'll use the table scott.emp to illustrate.

    Consider these data from scott.emp:

    SELECT DeptNo

    ename

    work

    FROM scott.emp

    ORDER BY deptno

    ename DESC

    ;

    Output:

    DEPTNO ENAME JOB

    ---------- ---------- ---------

    10 MILLER CLERK

    PRESIDENT OF KING 10

    MANAGER 10 CLARK

    20 SMITH CLERK

    ANALYST SCOTT 20

    20 JONES MANAGER

    20 FORD ANALYST

    20 ADAMS CLERK

    30 WARD SALESMAN

    SELLER OF 30 TURNER

    30 MARTIN SALESMAN

    30 JAMES CLERK

    MANAGER BLAKE 30

    30 ALLEN SALESMAN

    Now, let's say we want only who know the departments where the forefront (in order descending ename) a job = 'CLERK', and the following line (also in descending by ename order) = "ANALYST" job, and we want to know the ename of the first row.  In other words, the correct output is:

    DEPTNO ENAME

    ---------- ----------

    20 SMITH

    Note that deptno = 10 is not included, even if the first task is to "CLERK." that was because the second job in deptno = 10 is the "PRESIDENT", not "ANALYST."

    Here's a way to get these results:

    WITH got_analytics AS

    (

    SELECT ename, deptno, job

    ROW_NUMBER () OVER (PARTITION BY deptno

    ORDER BY ename DESC

    ) AS r_num

    LEAD (employment) OVER (PARTITION BY deptno

    ORDER BY ename DESC

    ) AS next_job

    FROM scott.emp

    )

    SELECT deptno, ename

    OF got_analytics

    WHERE r_num = 1

    AND job = 'CLERK '.

    AND next_job = 'ANALYST '.

    ;

    I hope that answers your question.

    If this isn't the case, then, as Dan (and the FAQ forum) said, post CREATE TABLE and INSERT statements for some sample data and the exact results you want from these data.

    Post your query, based on the one I have posted more top and ponit out where he gets results.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002#9362002

  • How to set this point as well COSTS in Oracle Asset R12.1.3

    Hello

    I created po and invoice with the assets of the clearing account or CIP Clearing and I transferred to the assets of the oracle. Prepare more mass, how can I set this as well COSTS. I already have active cost in the asset class.

    You need help!

    Thank you

    Hello

    If the query is "assets of Oracle can allow conversion of an asset Capital/CIP to a credit to expense at the stage of adding mass?"

    The answer looks like no.... I did a below test case myself to see the results.
    (1) created invoice to pay with the active account temporary, valid, approved, represents the invoice...
    (2) transferred to GL and linked the process of creating massive addition of accounts payable
    (3) asset, went to the screen adding mass to prepare...
    (4) questioned a line of addition of mass with the NEW status
    (5) in assets Details TAB, the type of property for my line is uppercase. I tried to change that in Expensed, while I can't change because the active type of expense is not listed in the drop-down options menu... I choose PAC or type of assets of the group, but not charged to the exercise...

    I tried another approach, by selecting a category (cool) for my line of massive addition, it will allow to change the type of assets or not... rather it throwed the below error message...

    «APP-OFA-48201 error: error incorrect asset Type and category combination for & stuff»

    In seeking the support of oracle with the above error reference came across the note below...
    165827.1 ID = APP-OFA-48201 when changing the category to prepare mass additions

    who says:

    "FA only allows assets reclassified between capitalized categories or between categories has expensed. Assets may not be reclassified between categories past expensed and capitalized. "

    I'm assuming that the conclusion or you can change the type of assets of immobilized to Expensed to the massive addition step prepared... .you could either remove the line and assets (load) to create manually...

    Kind regards
    Ivruksha

  • How to write this query in the hierarchy

    Hi gurus,

    Really need your help on this query.  Thank you very much in advance.

    SELECT
      t1.key as root_key ,
    (SELECT
          t2.unit_id AS unit_id 
          level-1 AS level ,
          t2.name,
          t2.creator
        FROM
          tab t2
          START WITH t2.unit_id       =   t1.unit_id            -----check each node as root
          CONNECT BY prior t2.unit_id = t2.parent_unit_id
    
      )
       t1.name as parent_unit_name
    FROM
      tab t1
    

    I'll write a query of the hierarchy as above, and that EACH line (node, totally more than 10200) is checked as root node to see how many sheets are accessible for her... It must be implemented in a single query.

    I know inline query should NOT return multiple rows or multiple columns, but the inline elements are necessary and can certainly be made in a correct solution.

    (env):

    Database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production

    PL/SQL Release 12.1.0.2.0

    )

    Test data:

    select 1 as unit_id, null as parent_organization_unit_id, 'U1' as name from dual
    union all
    select 2, 1, 'U2' FROM DUAL
    UNION ALL
    SELECT 3, NULL, 'U3' FROM DUAL
    UNION ALL
    SELECT 4, 3, 'U4' FROM DUAL
    UNION ALL
    SELECT 5, 2, 'U5' FROM DUAL
    UNION ALL
    SELECT 6, 5, 'U6' FROM DUAL
    UNION ALL
    SELECT 7, 6, 'U7' FROM DUAL
    UNION ALL
    SELECT 8, 5, 'U8' FROM DUAL
    UNION ALL
    SELECT 9, 5, 'U9' FROM DUAL;
    

    Final result should be like this

    key unit_id,    level,   name, parent_name
    1    1    0    u1      u1
    1    2    1    u2       u1
    1    5    2     u5      u1
    1    6    3     u6      u1
    1    7    4    u7       u1
    1    8    3    u8       u1
    1    9    3     u9      u1
    2    2    0     u2       u2
    2    5    1      u5       u2
    2    6    2     u6       u2
    2    7    3      u7      u2
    2    8    2      u8       u2
    2    9    2      u9       u2
    
    

    Don't know how get you your output, it does not match your data...

    with tab as)

    Select 1 as unit_id, null as parent_organization_unit_id 'U1' as the name of double

    Union of all the

    Select 2, 1, 'U2' FROM DUAL

    UNION ALL

    SELECT 3, NULL, 'U3' FROM DUAL

    UNION ALL

    SELECT 4, 3, 'U4' FROM DUAL

    UNION ALL

    SELECT 5, 2, 'U5' OF THE DOUBLE

    UNION ALL

    SELECT 6, 5, 'U6' OF THE DOUBLE

    UNION ALL

    SELECT 7, 6, "U7" OF THE DOUBLE

    UNION ALL

    SELECT 8, 5, 'U8' FROM DUAL

    UNION ALL

    9. SELECT, 5, 'U9' FROM DUAL

    )

    Select dense_rank() key (order by connect_by_root unit_id), unit_id, level - 1 as 'LEVEL', connect_by_root name root_parent_name

    t tab

    Start with parent_organization_unit_id is null

    Connect prior unit_id = parent_organization_unit_id

    KEY UNIT_ID LEVEL ROOT_PARENT_NAME
    1 1 0 "U1".
    1 2 1 "U1".
    1 5 2 "U1".
    1 6 3 "U1".
    1 7 4 "U1".
    1 8 3 "U1".
    1 9 3 "U1".
    2 3 0 "U3".
    2 4 1 "U3".
  • How to simplify this query in sql simple select stmt

    Hello

    Please simplify the query

    I want to convert this query in a single select statement. Is this possible?
    If uarserq_choice_ind is not null then

    Select ubbwbst_cust_code
    From ubbwbst,utrchoi
    Where utrchoi_prop_code=ubbwbst_cancel_prod
    Else

    Select max(utvsrvc_ranking)
    From utvsrvc,ubbwbst
    Where utvsrvc_code=ubbwbst_cancel_prod
    End if
    Select ubbwbst_cust_code as val
    From   ubbwbst,utrchoi
    Where  utrchoi_prop_code=ubbwbst_cancel_prod
    AND    uarserq_choice_ind is not null
    union all
    Select max(utvsrvc_ranking) as val
    From   utvsrvc,ubbwbst
    Where  utvsrvc_code=ubbwbst_cancel_prod
    and    uarserq_choice_ind is null
    

    Without more information, we are unable to combine the two queries in 1 without a union.
    Looks like you select values totally disperate of totally different tables

  • How to rewrite this query to get the correct results?

    Friends,

    DB: 9iR2

    I need to get the name of the employee and the employee number that are not in the table of presence.
    but this query is not the right answer.
    select e.eno,e.ename from empl e
    where e.eno not in (select a.eno from attendance a)
    Thank you

    Depending on your data

    SQL> create table attendance(
      2  ENO   VARCHAR2(5),
      3   TDATE VARCHAR2(10),
      4   IN_TIME  VARCHAR2(6),
      5   OUT_TIME VARCHAR2(6),
      6   SHIFT_NO  NUMBER(1));
    
    Table created.
    
    SQL>  create table empl(
      2   ENO VARCHAR2(5),
      3   ENAME  VARCHAR2(75));
    
    Table created.
    
    SQL> insert into empl values('11','AA');
    
    1 row created.
    
    SQL>   insert into empl values('12','AB');
    
    1 row created.
    
    SQL>    insert into empl values('13','AC');
    
    1 row created.
    
    SQL>     insert into empl values('14','AD');
    
    1 row created.
    
    SQL>   insert into empl values('15','AF');
    
    1 row created.
    
    SQL>  insert into attendance values('11','23-3-2009','9.00','6.00',1);
    
    1 row created.
    
    SQL>  insert into attendance values('14','24-3-2009','9.00','6.00',1);
    
    1 row created.
    
    SQL>  insert into attendance values('11','25-3-2009','9.00','6.00',1);
    
    1 row created.
    
    SQL>  insert into attendance values('13','23-3-2009','9.00','6.00',1);
    
    1 row created.
    
    SQL>  insert into attendance values('15','23-3-2009','9.00','6.00',1);
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    select e.eno,e.ename
    from empl e
    where not exists(select 1 from attendance a where a.eno=e.eno);
    
    ENO     ENAME
    
    12     AB
    

    Twinkle

  • Is it possible to set this query...

    This query takes 10 minutes to run on Windows 2003, raid10, Oracle 10.2.0.4.Is it doesn't matter what part I can watch in optimizing the query...

    Withdrawal of the request...
    Published by: Maran Viswarayar on 13 Nov 2009 13:51

    Published by: Maran Viswarayar on November 16, 2009 14:58

    Try something like this I tested with the substr function:

    SQL> select substr(pad,2,3) from t where id=368;
    
    SUB
    ---
    WET
    
    SQL> select substr((select pad from t where id=368),2,3) from dual;
    
    SUB
    ---
    WET
    

    I used the sql statement to replace the function parameter. Of course, it's stupid to use this way, if you do not need to do, but for your case, this could be a solution. In your case, you could write:

    FROM TABLE (ADMIN.find_record_dtl (
                         8,
                         (select SUBSTR(pc.pay_calendar_id, 0,3) from pr_calendar pc where  = SUBSTR(pc.pay_calendar_id, 0,3) = 'RET')),
                         'HQPRM003')
    

    Therefore, you put any sql that returns the correct value for your second parameter to your function entry. I hope that I wrote the right of expression, like yesterday, I got some garbage inside the text when I copied it.

    From the performance point of view I wouldn't function to extract the lines although it uses in BULK COLLECT but would rather use SQL function and integrate it within the main query and get something like:

    ...FROM( SELECT  DISTINCT pc.pay_calendar_id,
                     CASE WHEN ...
                     END AS pay_amount,
               rd.employee_id, cal_month, data_name, data_desc, data_seq
               FROM (SELECT distinct report_id, employee_id,  employee_name,
                                     pay_calendar_id, data_name, data_desc,
                                  data_seq, display_name, section_seq,
                                  item_id, base_amt, input_amt,
                                  calculated_amt
                        FROM list_record_dtl) rd,
                            pr_calendar pc
                 WHERE pc.pay_calendar_id = rd.pay_calendar_id
                 AND   SUBSTR(pc.pay_calendar_id, 0,3) = 'RET'
                 AND   rd.employee_id = 'HQPRM003'
                       and   rd.report_id = 8 ) a
             RIGHT JOIN ....
    

    So now you have two options yet :-)

    Generally, I would prefer rather to not use the service for the following reasons:
    (1.) the change of context between engine sql and pl/sql - Fortunately, in your case the function is executed only once (see column starts from your execution plan)
    2.) xxx of the instances of the type of data pay_item_t to the result of the query within the service may use lots of memory. This memory is allocated to the PGA and would be seen in v$ process_memory in the category 'other '. Of course, you can also monitor the consumption of memory of PGA of v$ sesstat. Now you will use the three parameters to the function and fewer rows returned as it was before, when the function has returned 192076 lines.
    3.) and the last one the more important one - if you use the online mode you give the CBO opportunity to optimize instruction. If you are using the CBO cannot push the predicates of main query within the query that is executed within the function and so it can be like a suboptimal plan even what exactly was your case when you started this thread. Was clearly the person who developed the conscious function of this problem and has tried to solve this problem by additional parameters that are passed to the function and are used to limit the number of rows returned by the function. Unfortunately these two parameters were not used in your case.
    4.) it is always a good practice using only the resources you really need and not much more!

    Published by: Scheid Joze on 19.11.2009 10:50

  • How ot do this query

    some of you that it won't be easy, but for a rookie plsql is not form. Can U help?

    want to find out who has max (salary) and record that information in a variable

    Table: used
    id  salary
    1    2000
    2    2500
    3    1800
    Select max (salary) in employee == > back 2500
    But how to write this in a plsql and find the id is 3 and save it in a variable


    my incomplete statement:

    Select max (salary), in myvar to employee where id =?

    can you help me?

    Oh and save it in a variable plsql:

    declare my_var emp.empno%TYPE;
    begin
      select e1.empno into my_var
      from emp e1
      where e1.sal = (select max(e2.sal) from emp e2)
        and rownum = 1;
    end;
    /
    
  • How to solve this query in database using sqlite phone gap

    am facing a problem in recent days. The problem is database. In fact, I create the mane database 'casepad '. Then I created a table because the database 'table of cases' have (ID, name, date). Now I insert the value on this table. When inserting I also create a name ("casename") .mean table if I insert the value of the case table (1, 'AB', 2/13). Then I create table AB. Now I need to get the value of the case table (I am) but I need to count the number of items in another table (AB). Here, I had to try it.

    function onDeviceReady() {
    
        db = window.openDatabase("Casepad", "1.0", "Casepad", 200000);
    
    db.transaction(getallTableData, errorCB);
    
    }
    
    function insertData() {
        db.transaction(createTable, errorCB, afterSuccessTableCreation);
    }
    
    //createtableandinsertsome record
    function createTable(tx) {
        tx.executeSql('CREATE TABLE IF NOT EXISTS CaseTable (id INTEGER PRIMARY KEY AUTOINCREMENT, CaseName  TEXT unique NOT NULL ,CaseDate INTEGER ,TextArea TEXT NOT NULL)');
    
        tx.executeSql('INSERT OR IGNORE INTO CaseTable(CaseName,CaseDate,TextArea) VALUES ("' + $('.caseName_h').val() + '", "' + $('.caseDate_h').val() + '","' + $('.caseTextArea_h').val() + '")');
    
    }
    //function will be called when an error occurred
    function errorCB(err) {
        navigator.notification.alert("Error processing SQL: " + err.code);
    }
    
    //function will be called when process succeed
    function afterSuccessTableCreation() {
        console.log("success!");
        db.transaction(getallTableData, errorCB);
    }
    
    //select all from SoccerPlayer
    function getallTableData(tx) {
        tx.executeSql('SELECT * FROM CaseTable', [], querySuccess, errorCB);
    }
    
    function querySuccess(tx, result) {
        var len = result.rows.length;
        var t;
        $('#folderData').empty();
        for (var i = 0; i < len; i++) {
    
            $('#folderData').append(
                    '
  • ' + '' + '' + '

    ' + result.rows.item(i).CaseName + t+'

    ' + '

    ' + result.rows.item(i).TextArea + '

    ' + '

    ' + result.rows.item(i).CaseDate + '

    ' + '' + i + '
    ' + '
    '+'
  • ' ); } $('#folderData').listview('refresh'); }

    Instend of show the value of 'i' in the view list, I need to show how many element in the table. I have to call synchronize because I call a query that counts the number of elements to 'result.rows.item (i). CaseName"this item... ?

    Hello

    If I understand correctly, you are looking for a SQL statement that you will get the count for the number of items in the table AB? If so, this can be useful:

    http://www.w3schools.com/SQL/sql_func_count.asp

    Please let me know if you have any other questions.

  • How to optimize this query XMLDB

    Hello dear community, we have two XMLType table they are very similar but not identical and we do not have the XSD for validation for this exercise.

    We need to make a join between these tables and the data code example go like that

    create table xmltst ( xmldata xmltype);
    create table xmltst2 ( xmldata xmltype);
    
    declare
     idata varchar2(4000);
     idata2 varchar2(4000);
     begin
    
     idata := '<?xml version="1.0" encoding="UTF-8"?>
    <SWs>
      <SW s_ID="T6B890.00-01" t_ID="T6B890.00">
      <Ds>
      <De sX="59" sY="-57" rX="7" rY="22" m_ID="L" eTime_s="2014-12-12T02:22:11+08:00" eTime_e="2014-12-12T02:22:42+08:00" mst="0.631"/>
      <De sX="70" sY="-57" rX="7" rY="23" m_ID="L" eTime_s="2014-12-12T02:22:12+08:00"  eTime_e="2014-12-12T02:22:33+08:00" mst="0.217"/>
      <De sX="69" sY="-57" rX="47" rY="1" m_ID="R" eTime_s="2014-12-12T02:22:16+08:00" eTime_e="2014-12-12T02:22:56+08:00" mst="0.974"/>
      </Ds>
      </SW>
      <SW s_ID="T6B890.00-02" t_ID="T6B890.00">
      <Ds>
      <De sX="56" sY="-1" rX="72" rY="19" m_ID="R" eTime_s="2014-12-12T02:36:01+08:00" eTime_e="2014-12-12T02:36:29+08:00" mst="0.541"/>
      <De sX="57" sY="-1" rX="39" rY="42" m_ID="L" eTime_s="2014-12-12T02:22:12+08:00" eTime_e="2014-12-12T02:23:01+08:00" mst="0.426"/>
      <De sX="58" sY="-1" rX="72" rY="20" m_ID="R" eTime_s="2014-12-12T02:36:07+08:00" eTime_e="2014-12-12T02:36:18+08:00" mst="0.716"/>
      </Ds>
      </SW>
    </SWs>';
    
    
    idata2 := '<?xml version="1.0" encoding="UTF-8"?>
    <SWs>
      <SW s_ID="T6B890.00-01" t_ID="T6B890.00">
      <Ds>
      <De sX="59" sY="-57" rX="7" rY="22" m_ID="L" eTime_s="2014-12-12T02:22:11+08:00" eTime_e="2014-12-12T02:22:42+08:00"/>
      <De sX="70" sY="-57" rX="7" rY="23" m_ID="L" eTime_s="2014-12-12T02:22:12+08:00" eTime_e="2014-12-12T02:22:33+08:00"/>
      <De sX="69" sY="-57" rX="47" rY="1" m_ID="R" eTime_s="2014-12-12T02:22:16+08:00" eTime_e="2014-12-12T02:22:56+08:00"/>
      <De sX="72" sY="-57" rX="47" rY="2" armID="R" eTime_s="2014-12-12T02:22:18+08:00" eTime_e="2014-12-12T02:23:28+08:00"/>
      <De sX="82" sY="-57" rX="7" rY="25" armID="L" eTime_s="2014-12-12T02:22:19+08:00" eTime_e="2014-12-12T02:22:58+08:00"/>
      </Ds>
      </SW>
      <SW s_ID="T6B890.00-02" t_ID="T6B890.00">
      <Ds>
      <De sX="56" sY="-1" rX="72" rY="19" m_ID="R" eTime_s="2014-12-12T02:36:01+08:00" eTime_e="2014-12-12T02:36:29+08:00"/>
      <De sX="57" sY="-1" rX="39" rY="42" m_ID="L" eTime_s="2014-12-12T02:22:12+08:00" eTime_e="2014-12-12T02:23:01+08:00"/>
      <De sX="58" sY="-1" rX="72" rY="20" m_ID="R" eTime_s="2014-12-12T02:36:07+08:00" eTime_e="2014-12-12T02:36:18+08:00"/>
      </Ds>
      </SW>
    </SWs>';
    
    
    
    insert into xmltst values (idata);
    insert into xmltst2 values (idata2);
    
    
    end;
    
    
    commit;
    

    The SQL code, we try to optimize:

    with tt as (    
    SELECT /*+ materialize */
       x.*
         FROM xmltst t,
              XMLTABLE ('/SWs/SW[@s_ID="T6B890.00-01"]/Ds/De'
                        PASSING t.xmldata
                        COLUMNS sX number  PATH '@sX',
                                sY number  PATH '@sY',
                                rX number PATH '@rX',
                                rY number PATH '@rY',
                                eTime_s varchar2(30) PATH '@eTime_s',
                                eTime_e varchar2(30) PATH '@eTime_e',
                                mst number PATH '@mst'
                                ) x     
                                )
                                ,tt2 as (
                                
    SELECT /*+ materialize */
       x.*
         FROM xmltst2 t,
              XMLTABLE ('/SWs/SW[@s_ID="T6B890.00-01"]/Ds/De'
                        PASSING t.xmldata
                        COLUMNS sX number  PATH '@sX',
                                sY number  PATH '@sY',
                                rX number PATH '@rX',
                                rY number PATH '@rY',
                                eTime_s varchar2(30) PATH '@eTime_s',
                                eTime_e varchar2(30) PATH '@eTime_e'                            
                                ) x        
                                )
                                select tt2.*,tt.mst
                                from tt2
                                left outer join tt
                                on (tt2.sX = tt.sX and tt2.sY = tt.sY and tt2.rX = tt.rX and tt.rY=tt.rY)
    

    CREATE INDEX xmltst_idx ON xmltst (xmldata)
    INDEXTYPE IS XDB.XMLIndex
    PARAMETERS (
    'XMLTable SW_tab ''/SWs/Sw''
     COLUMNS 
     s_ID VARCHAR2(100) PATH ''@s_ID'',
     sX NUMBER PATH ''Ds/De/@sX'',
     sY NUMBER PATH ''Ds/De/@sY'',
     rX NUMBER PATH ''Ds/De/@rX'',
     rY NUMBER PATH ''Ds/De/@rY''');
    

    Create an index as above, but it does not seem to be used to explain the plan for the part of XML query.

    and a lot of time, I also get this error but I cannot now re - produce for some reason.

    I thought that its because I can't index after branch out according to s_ID

    SQL Error: ORA-29879: cannot create multiple domain indexes on a column list using same indextype
    29879. 00000 -  "cannot create multiple domain indexes on a column list using same indextype"
    *Cause:    An attempt was made to define multiple domain indexes on the same
               column list using identical indextypes.
    *Action:   Check to see if a different indextype can be used or if the index
               can be defined on another column list.
    

    and this index below seems to have choice as shown explain plan.

    Why can't I see the index above in the plan to explain it?

      CREATE INDEX "OE"."XMLTST_INDX01" ON "OE"."XMLTST" ("XMLDATA") 
       INDEXTYPE IS "XDB"."XMLINDEX"  PARAMETERS ('paths (include (/SWs/SW/@s_ID))');
    

    However, it is still the loop nest join when the join of two tables after the XML in the process... Is it possible to tell Oracle to a join index or some kind of faster join after the XML select part.

    My real case got way as many lines to make the join of X - Y and it may be nice to have an index to quickly reach?

    When do some small tests, the clause will eventually cause oracle core dump. It should not happen even it is a virtual machine with 3G of memory max and the max_memory_target = 800 M as all my data are not not even 50 M.

    We are the team of analysts and Dev team suggest that is a little too much time to contact Oracle Support and I finally create 3 global temporary table with commit preserve rows and operate with performance much better.

Maybe you are looking for