simplify a query

Hi all

on 11.2.0.4 on Windows

The following query works:

SQL > select name, grip, duration, to_number (to_char(adhesion,'yy')) + duration mydate, to_number (to_char (sysdate, 'yy')) members Mr kdate

2 where to_number (to_char (sysdate, 'yy'))-(to_number (to_char(adhesion,'yy')) + length) > = 2;

LENGTH OF NAME MYDATE KDATE GRIP

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

LOMOBO AUGUST 2, 12 1 13 15

I try to write in a simpler way, but does not work:

SQL > select name, grip, duration, to_number (to_char(adhesion,'yy')) + duration mydate, to_number (to_char (sysdate, 'yy')) members Mr kdate

2 where kdate-mydate > = 2;

where kdate-mydate > = 2

*

ERROR on line 2:

ORA-00904: "MANDATE": invalid identifier

Thanks for help.

A select statement with a view online is always a single select statement. But I get your point. You can't refer to an alias specified for a column name in a select statement in a where clause of the statement itself select clause.

Also, your technique of conversion applied to get the year does not look good. You used the AA. Year has 4 numbers if you want to subtract 2099 and 1999 your approach will return 0. If you can tell what you're trying to achieve we can help you to solve it in an appropriate way without going over everything that conversions.

Tags: Database

Similar Questions

  • Can anyone simplify this query

    Here's a DOF from two tables

    1. CREATE TABLE (EMPL)
    NUMBER OF SNO
    ENAME VARCHAR2 (25).
    USE VARCHAR2 (25).
    KEY ELEMENTARY SCHOOL (SNO)
    );

    2. CREATE TABLE EMPL_DET)
    NUMBER OF SNO
    SAL VARCHAR2 (25)
    );


    Here are tables LMD
    INSERT INTO EMPL (SNO, ENAME, JOB) VALUES (1, 'SMITH', 'CLERK');
    INSERT INTO EMPL (SNO, ENAME, JOB) VALUES (2, 'SMITH', 'MANAGER');
    INSERT INTO EMPL (SNO, ENAME, JOB) VALUES (3, 'TOM', 'CLK');

    INSERT INTO EMPL_DET (SNO, SAL) VALUES (1, '1000');
    INSERT INTO EMPL_DET (SNO, SAL) VALUES (2, "10000");
    INSERT INTO EMPL_DET (SNO, SAL) VALUES (3, '900');


    I want to calculate TotalSAL (column: empl_det.) SAL) of each employee (empl.ename) with job-description (empl.job).

    Means I want following the lines of output
    1.(Job,TotalSAL,Ename)-> (CLERK, 11000, SMITH)
    2->.(Job,TotalSAL,Ename) (MANAGER, 11000, SMITH)
    3->.(Job,TotalSAL,Ename) (CLK, 900, TOM)

    I tried to write down to unique ename

    Select JOB, x.sal, ename in empl,
    (
    Select sum (sal) sal empl_det where sno in
    (select sno to empl where ename = 'SMITH')
    ) x
    where ename = 'SMITH '.
    order by ename

    each ename, I draw from this query. How can I make the ename list (TOM SMITH) to this request?
    Or can anyone simplify this query?

    Hello

    in this case, you need to use is analytical functions:

    that is to say:

      SELECT e.job, SUM (d.sal) OVER (PARTITION BY e.ename) AS "TotalSal"
           , e.ename
        FROM empl e, empl_det d
       WHERE d.sno = e.sno AND e.ename IN ('SMITH', 'TOM')
    ORDER BY e.ename;
    
    JOB                         TotalSal ENAME
    ------------------------- ---------- -------------------------
    CLERK                          11000 SMITH
    MANAGER                        11000 SMITH
    CLK                              900 TOM                      
    

    Kind regards.
    Al

    Published by: Alberto Faenza on 27 November 2012 15:34
    Corrected query

  • 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

  • [8i] not to simplify this query?

    In my application, I need to pick up three possible prices for each part number in an array.
    The three possible prices that I need to recover are:
    (1) the price paid on the order more recently closed,
    (2) the price mentioned on the first pending order, and
    (3) the price on the furthest on pending order.

    However, there is a complication in that. Orders include the part number, but may also include a prefix of 4 characters (always the same) on a reference number which should be treated the same as the reference database. For example, "DSB-part1" should be considered "part1", "DSB-part2" should be regarded as 'part 2', etc.

    In addition, it is quite possible for several orders expected or closed on the same day, and I want to only return the price of one of these lines for each of the 3 methods of pricing.

    (Technically, there is another level of complication to this, but if I have problems with it later, I'll create a new job for him...)

    Some examples of data:
    CREATE TABLE     part
    (     part_no          VARCHAR2(9)     NOT NULL,
         part_desc     VARCHAR2(25),
         qty_instock     NUMBER,
         CONSTRAINT part_pk PRIMARY KEY (part_no)
    );
    
    INSERT INTO     part
    VALUES ('part1    ','description 1 here',5);
    INSERT INTO     part
    VALUES ('part2    ','description 2 here',10);
    INSERT INTO     part
    VALUES ('part3    ','description 3 here',0);
    
    CREATE TABLE     ords
    (     ord_no               NUMBER NOT NULL,
         ord_part_no          VARCHAR2(9),
         date_closed          DATE,
         orig_dock_date          DATE,
         date_due_instock     DATE,
         unit_price          NUMBER,
         qty_order          NUMBER,
         ord_stat          VARCHAR2(2),
         CONSTRAINT ords_pk PRIMARY KEY (ord_no)
    );
    
    INSERT INTO     ords
    VALUES (1,'part1    ',To_Date('01/01/2009','mm/dd/yyyy'),To_Date('12/01/2008','mm/dd/yyyy'),To_Date('12/15/2008','mm/dd/yyyy'),100,10,'CL');
    INSERT INTO     ords
    VALUES (2,'part1    ',To_Date('01/31/2009','mm/dd/yyyy'),To_Date('01/01/2009','mm/dd/yyyy'),To_Date('01/05/2009','mm/dd/yyyy'),105,15,'CL');
    INSERT INTO     ords
    VALUES (3,'part1    ',To_Date('01/31/2009','mm/dd/yyyy'),To_Date('01/15/2009','mm/dd/yyyy'),To_Date('01/20/2009','mm/dd/yyyy'),100,20,'CL');
    INSERT INTO     ords
    VALUES (4,'part1    ',To_Date('12/31/1900','mm/dd/yyyy'),To_Date('01/15/2009','mm/dd/yyyy'),To_Date('01/25/2009','mm/dd/yyyy'),103,10,'OP');
    INSERT INTO     ords
    VALUES (5,'ORD-part1',To_Date('12/31/1900','mm/dd/yyyy'),To_Date('01/20/2009','mm/dd/yyyy'),To_Date('01/31/2009','mm/dd/yyyy'),101,10,'OP');
    
    INSERT INTO     ords
    VALUES (6,'ORD-part2',To_Date('01/01/2009','mm/dd/yyyy'),To_Date('12/01/2008','mm/dd/yyyy'),To_Date('12/15/2008','mm/dd/yyyy'),100,10,'CL');
    INSERT INTO     ords
    VALUES (7,'part2    ',To_Date('01/31/2009','mm/dd/yyyy'),To_Date('01/01/2009','mm/dd/yyyy'),To_Date('01/05/2009','mm/dd/yyyy'),105,15,'CL');
    INSERT INTO     ords
    VALUES (8,'ORD-part2',To_Date('01/31/2009','mm/dd/yyyy'),To_Date('01/15/2009','mm/dd/yyyy'),To_Date('01/20/2009','mm/dd/yyyy'),100,20,'CL');
    INSERT INTO     ords
    VALUES (9,'part2    ',To_Date('12/31/1900','mm/dd/yyyy'),To_Date('01/15/2009','mm/dd/yyyy'),To_Date('01/25/2009','mm/dd/yyyy'),103,10,'OP');
    INSERT INTO     ords
    VALUES (10,'ORD-part2',To_Date('12/31/1900','mm/dd/yyyy'),To_Date('01/20/2009','mm/dd/yyyy'),To_Date('01/31/2009','mm/dd/yyyy'),101,10,'OP');
    
    INSERT INTO     ords
    VALUES (11,'part3    ',To_Date('01/01/2009','mm/dd/yyyy'),To_Date('12/01/2008','mm/dd/yyyy'),To_Date('12/15/2008','mm/dd/yyyy'),100,10,'CL');
    INSERT INTO     ords
    VALUES (12,'part3    ',To_Date('01/31/2009','mm/dd/yyyy'),To_Date('01/01/2009','mm/dd/yyyy'),To_Date('01/05/2009','mm/dd/yyyy'),105,15,'CL');
    INSERT INTO     ords
    VALUES (13,'ORD-part3',To_Date('01/31/2009','mm/dd/yyyy'),To_Date('01/15/2009','mm/dd/yyyy'),To_Date('01/20/2009','mm/dd/yyyy'),100,20,'CL');
    INSERT INTO     ords
    VALUES (14,'ORD-part3',To_Date('12/31/1900','mm/dd/yyyy'),To_Date('01/15/2009','mm/dd/yyyy'),To_Date('01/25/2009','mm/dd/yyyy'),103,10,'OP');
    INSERT INTO     ords
    VALUES (15,'part3    ',To_Date('12/31/1900','mm/dd/yyyy'),To_Date('01/20/2009','mm/dd/yyyy'),To_Date('01/31/2009','mm/dd/yyyy'),101,10,'OP');
    And here's my ugly query to get the results I want. It can be simplified?
    SELECT     p.part_no
    ,     p.part_desc
    ,     p.qty_instock
    ,     a2.unit_price          AS last_closed_price
    ,     a2.qty_order          AS last_closed_qty
    ,     a2.date_closed          AS last_closed_date
    ,     b2.unit_price          AS first_open_price
    ,     b2.qty_order          AS first_open_qty
    ,     b2.date_due_instock     AS first_open_date
    ,     c2.unit_price          AS last_open_date
    ,     c2.qty_order          AS last_open_qty
    ,     c2.date_due_instock     AS last_open_date
    FROM     part p
    ,     (
         SELECT     lc.part_no
         ,     lc.unit_price                                             
         ,     lc.qty_order
         ,     lc.date_closed
         ,     ROW_NUMBER() OVER(PARTITION BY lc.part_no ORDER BY lc.orig_dock_date DESC)     AS rnk_nbr
         FROM     (
              SELECT     CASE
                        WHEN     SUBSTR(o.ord_part_no,1,4)     = 'ORD-'
                        THEN     SUBSTR(o.ord_part_no,5)
                        ELSE     o.ord_part_no
                   END                                        AS part_no
              ,     o.date_closed
              ,     o.orig_dock_date
              ,     o.unit_price
              ,     o.qty_order
              FROM     ords o
              ) lc     --for last closed
         ,     (
              SELECT     a.part_no
              ,     MAX(a.date_closed)     AS last_closed_date
              FROM     (
                   SELECT     CASE
                             WHEN     SUBSTR(o.ord_part_no,1,4)     = 'ORD-'
                             THEN     SUBSTR(o.ord_part_no,5)
                             ELSE     o.ord_part_no
                        END                                        AS part_no
                   ,     o.date_closed
                   FROM     ords o
                   ) a
              GROUP BY     a.part_no
              ) a1
         WHERE     lc.part_no     = a1.part_no
         AND     lc.date_closed     = a1.last_closed_date
         ) a2
    ,     (
         SELECT     fo.part_no
         ,     fo.unit_price                                             
         ,     fo.qty_order
         ,     fo.date_due_instock
         ,     ROW_NUMBER() OVER(PARTITION BY fo.part_no ORDER BY fo.orig_dock_date DESC)     AS rnk_nbr
         FROM     (
              SELECT     CASE
                        WHEN     SUBSTR(o.ord_part_no,1,4)     = 'ORD-'
                        THEN     SUBSTR(o.ord_part_no,5)
                        ELSE     o.ord_part_no
                   END                                        AS part_no
              ,     o.date_due_instock
              ,     o.orig_dock_date
              ,     o.unit_price
              ,     o.qty_order
              FROM     ords o
              WHERE     o.ord_stat     = 'OP'
              ) fo     --for first open
         ,     (
              SELECT     b.part_no
              ,     MIN(b.date_due_instock)     AS first_open_date
              FROM     (
                   SELECT     CASE
                             WHEN     SUBSTR(o.ord_part_no,1,4)     = 'ORD-'
                             THEN     SUBSTR(o.ord_part_no,5)
                             ELSE     o.ord_part_no
                        END                                        AS part_no
                   ,     o.date_due_instock
                   FROM     ords o
                   WHERE     o.ord_stat     = 'OP'
                   ) b
              GROUP BY     b.part_no
              ) b1
         WHERE     fo.part_no          = b1.part_no
         AND     fo.date_due_instock     = b1.first_open_date
         ) b2
    ,     (
         SELECT     lo.part_no
         ,     lo.unit_price                                             
         ,     lo.qty_order
         ,     lo.date_due_instock
         ,     ROW_NUMBER() OVER(PARTITION BY lo.part_no ORDER BY lo.orig_dock_date DESC)     AS rnk_nbr
         FROM     (
              SELECT     CASE
                        WHEN     SUBSTR(o.ord_part_no,1,4)     = 'ORD-'
                        THEN     SUBSTR(o.ord_part_no,5)
                        ELSE     o.ord_part_no
                   END                                        AS part_no
              ,     o.date_due_instock
              ,     o.orig_dock_date
              ,     o.unit_price
              ,     o.qty_order
              FROM     ords o
              WHERE     o.ord_stat     = 'OP'
              ) lo     --for last open
         ,     (
              SELECT     c.part_no
              ,     MAX(c.date_due_instock)     AS last_open_date
              FROM     (
                   SELECT     CASE
                             WHEN     SUBSTR(o.ord_part_no,1,4)     = 'ORD-'
                             THEN     SUBSTR(o.ord_part_no,5)
                             ELSE     o.ord_part_no
                        END                                        AS part_no
                   ,     o.date_due_instock
                   FROM     ords o
                   WHERE     o.ord_stat     = 'OP'
                   ) c
              GROUP BY     c.part_no
              ) c1
         WHERE     lo.part_no          = c1.part_no     --EDIT: changed from l1 to c1
         AND     lo.date_due_instock     = c1.last_open_date     --EDIT: changed from l1 to c1
         ) c2
    WHERE     p.part_no     = a2.part_no
    AND     a2.part_no     = b2.part_no
    AND     b2.part_no     = c2.part_no
    AND     a2.rnk_nbr     = 1
    AND     b2.rnk_nbr     = 1
    AND     c2.rnk_nbr     = 1
    And here are the results, I expect to get, according to data from the sample:
    .                         LAST_     LAST_     LAST_          FIRST_     FIRST_     FIRST_          LAST_     LAST_     LAST_
    .                    QTY_     CLOSED_     CLOSED_     CLOSED_          OPEN_     OPEN_     OPEN_          OPEN_     OPEN_     OPEN_
    PART_NO     PART_DESC          INSTOCK     PRICE     QTY     DATE          PRICE     QTY     DATE          PRICE     QTY_     DATE_
    ---------------------------------------------------------------------------------------------------------------------------------
    part1     description 1 here     5     100     20     1/31/2009     103     10     1/25/2009     101     10     1/31/2009
    part2     description 2 here     10     100     20     1/31/2009     103     10     1/25/2009     101     10     1/31/2009
    part3     description 3 here     0     100     20     1/31/2009     103     10     1/25/2009     101     10     1/31/2009
    Published by: user11033437 on February 5, 2010 08:48
    Correction of errors (see the comments in the request above for changes)

    Hello

    It is a little bit shorter than what you have posted, probably more effective and (in my opinion) much easier to debug and maintain:

    SELECT       p.part_no
    ,       p.part_desc
    ,       p.qty_instock
    ,       o.last_closed_price
    ,       o.last_closed_qty
    ,       o.last_closed_date
    ,       o.first_open_price
    ,       o.first_open_qty
    ,       o.first_open_date
    ,       o.last_open_price
    ,       o.last_open_qty
    ,       o.last_open_date
    FROM       part          p
    ,       (          -- Begin in-line view o for pivoted order data
               SELECT    part_no
               ,          MAX (CASE WHEN lc_num = 1 THEN unit_price           END)  AS last_closed_price
               ,          MAX (CASE WHEN lc_num = 1 THEN qty_order              END)  AS last_closed_qty
               ,          MAX (CASE WHEN lc_num = 1 THEN date_closed            END)  AS last_closed_date
               ,          MAX (CASE WHEN fo_num = 1
                                    AND  ord_stat = 'OP'  THEN unit_price       END)  AS first_open_price
               ,          MAX (CASE WHEN fo_num = 1
                                    AND  ord_stat = 'OP'  THEN qty_order        END)  AS first_open_qty
               ,          MAX (CASE WHEN fo_num = 1
                                    AND  ord_stat = 'OP'  THEN date_due_instock END)  AS first_open_date
               ,          MAX (CASE WHEN lo_num = 1
                                    AND  ord_stat = 'OP'  THEN unit_price       END)  AS last_open_price
               ,          MAX (CASE WHEN lo_num = 1
                                    AND  ord_stat = 'OP'  THEN qty_order        END)  AS last_open_qty
               ,          MAX (CASE WHEN lo_num = 1
                                    AND  ord_stat = 'OP'  THEN date_due_instock END)  AS last_open_date
               FROM     (       -- Begin in-line view to get lc_, fo_, lo_num
                             SELECT    gpo.*
                       ,           ROW_NUMBER () OVER ( PARTITION BY  part_no
                                                        ORDER BY        date_closed          DESC
                                          ,            ord_no               DESC
                                        )      AS lc_num
                       ,           ROW_NUMBER () OVER ( PARTITION BY  part_no
                                                        ORDER BY        CASE
                                                      WHEN  ord_stat = 'OP'
                                                      THEN  1
                                                      ELSE  2
                                                  END
                                          ,           orig_dock_date
                                          ,            ord_no
                                        )      AS fo_num
                       ,           ROW_NUMBER () OVER ( PARTITION BY  part_no
                                                        ORDER BY        CASE
                                                      WHEN  ord_stat = 'OP'
                                                      THEN  1
                                                      ELSE  2
                                                  END
                                          ,           orig_dock_date          DESC
                                          ,            ord_no               DESC
                                        )      AS lo_num
                       FROM      (       -- Begin in-line view gpo to get part_no
                                      SELECT  ords.*
                               ,       RTRIM ( CASE
                                            WHEN  ord_part_no  LIKE 'ORD-%'
                                                      THEN  SUBSTR (ord_part_no, 5)
                                                      ELSE  ord_part_no
                                                     END
                                       )               AS part_no
                               FROM       ords
                                  )     gpo   -- End in-line view gpo to get part_no
                         )      -- End in-line view to get lc_, fo_, lo_num
               GROUP BY  part_no
           ) o          -- End in-line view o for pivoted order data
    WHERE       RTRIM (p.part_no)     = o.part_no
    ORDER BY  p.part_no
    ;
    

    Whenever you want to have a WHERE clause only applies to certain columns, think about a pivot and expression BOX.

    Is there a reason to have raw triling part_no or ord_part_no?

    Published by: Frank Kulash, February 5, 2010 13:26

    After this announcement, I saw that Max had posted essentially the same query.
    In general, where the solution of Max seems more simple, I like her way better.
    The only possible exception is tested for "OP" at the derivation of the values first_open and last_open. If none of the lines to an ord_stat part_no = "OP", solution of Max will be used a the lines with another ord_stat. That does not occur in the sample data, and I don't know if this is still possible in your application, but if this is the case, I don't know this isn't what you want.

  • Need to simplify the query

    Hi gurus

    I have the following data:

    Drop table

    DROP TABLE lb_source;

    DROP TABLE lb;

    Insertion and table creation

    CREATE TABLE lb_source
    (
    source_cd VARCHAR2 (5)

    );


    INSERT INTO lb_source
    (
    SELECT 'a' STARTING from two
    UNION ALL
    SELECT 'b' double
    UNION ALL
    Select 'l' to double
    );

    CREATE TABLE lb
    (
    group_number VARCHAR2 (10),
    source_cd varchar2 (5)
    );

    INSERT INTO lb
    (
    SELECT '100', 'l' FROM dual
    UNION ALL
    SELECT '100', double null

    );

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

    If you see table lb then it contained a line with source_cd = l against 100 and source_cd = Null group against group 100, now I want to create this kind of query, in which all correspondence lines in tables to join both if lb is null, then query join all the source_cd of table lb_source except source_cd = 'l '. So far, I created the following query and its works ok but I want to do all my work in one in where condition...

    Query

    SELECT * FROM

    (

    SELECT s1, s2 b.source_cd A.source_cd

    OF lb_source A

    lb b

    WHERE A.source_cd = nvl (b.source_cd, A.source_cd)

    )

    WHERE s2 IS NULL

    ;

    Result

    s1 s2

    a null value

    b zero

    l null

    Please guide

    Hello

    So, you want something that produces the same accurate results as the query you posted, but does more just; Isn't it?

    Here's one way:

    SELECT ls.source_cd S1

    NULL AS s2

    OF ls lb_source

    JOIN lb l WE l.source_cd IS NULL

    AND ls.source_cd IS NOT NULL;

    I'm curious; What is the business problem that requires this request?  What tables and columns represent, and what tell you the query?

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

  • Simplify this query

    When I run this query, it will be 1 hour to run it. can we change this query to do this?
    SELECT /*+ CHOOSE */a.*, b.*
      FROM (SELECT (  TO_DATE (ucraudt_new_value, 'DD-MON-YYYY')
                    - TO_DATE (ucraudt_old_value, 'DD-MON-YYYY')
                   ) AS diff,
                   ucraudt.*
              FROM ucraudt
             WHERE ucraudt_column_code = '1GED'
               AND ucraudt_new_value IS NOT NULL
               AND ucraudt_old_value IS NOT NULL
               AND ucraudt_user_id LIKE 'UCPVCRV%') a,
           ucrserv b
    WHERE a.diff > 74
       AND a.ucraudt_cust_code = b.ucrserv_cust_code
       AND a.ucraudt_prem_code = b.ucrserv_prem_code
       AND b.ucrserv_status_ind = 'A'

    Try following

    SELECT
         a.*, b.*
    FROM
           ucraudt a,
           ucrserv b
     WHERE (TO_DATE (a.ucraudt_new_value, 'DD-MON-YYYY') - TO_DATE (a.ucraudt_old_value, 'DD-MON-YYYY'))  > 74
       AND a.ucraudt_cust_code = b.ucrserv_cust_code
       AND a.ucraudt_prem_code = b.ucrserv_prem_code
       AND b.ucrserv_status_ind = 'A'
       and a.ucraudt_column_code = '1GED'
       AND a.ucraudt_new_value IS NOT NULL
       AND a.ucraudt_old_value IS NOT NULL
       AND a.ucraudt_user_id LIKE 'UCPVCRV%' 
    

    Also post the query execution plan

  • Simplify the query by using Analytics

    Hi gurus,
    I need to humiliate you help by simplifying the application, as shown below:

    with REC_GRP_CNT as (select round (count (*) / 3) HML_CNT of JJVC_ACTIVITY_FREQ_RECENCY).
    REC_RANK as
    (select a.*, rownum rn of)
    Select custid, ((total_edm_opened/total_edm_delivered) * 100) percentage from JJVC_ACTIVITY_FREQ_RECENCY by 2 desc) a).
    FREQUENCY_HIGH like)
    Select custid, 'H' rec_rank FREQUENCY_RANK where rn < = (select HML_CNT FROM REC_GRP_CNT)).
    FREQUENCY_MEDIUM like)
    Select custid, I ' rec_rank a FREQUENCY_RANK
    where
    not exist (select custid from b FREQUENCY_HIGH where b.custid = a.custid)
    and rn < = (select HML_CNT * FROM REC_GRP_CNT 2)).
    FREQUENCY_LOW like)
    Select custid, 'L' rec_rank a FREQUENCY_RANK
    where
    not exists(select * from)
    (select custid from FREQUENCY_HIGH
    Union of all the
    custid SELECT of FREQUENCY_MEDIUM p) WHERE the p.custid = a.custid)
    and rn > = (select HML_CNT * 2 OF REC_GRP_CNT))
    Select * from FREQUENCY_HIGH
    Union of all the
    Select * from FREQUENCY_MEDIUM
    Union of all the
    Select * from FREQUENCY_LOW


    Thanks in advance,
    BTF

    You are going to have to explain what you mean by

    Total records H=33.3%
    Total records M=33.3%
    Total records L=33.4%

    What criteria do you use to create these "buckets" that fall under the data?

  • Need to simplify a query

    Brief description of the data and the sample data is in the second post:
    I have to take the following data:
    BUSINESSDATE STORENBR DESCRIPTION     CAT_COST               CAT_IN                 cat_s&h                
    ------------ -------- --------------- ---------------------- ---------------------- ----------
    21-MAR-10    0002     chicken         1450.34                0                      0                      
    21-MAR-10    0002     filets          357.2                  0                      0                      
    21-MAR-10    0002     popcorn_chicken 204.6                  0                      0                      
    21-MAR-10    0003     chicken         2064.38                117.96                 0                      
    21-MAR-10    0003     filets          494                    0                      0  
    and make it look like this:

    store     inv_date     chicken     chicken_in     chicken_S&H     filets     filets_in     filets_S&H     popcorn_chicken     popcorn_chicken_in     popcorn_chicken_S&H
    43     4/4/2010     1284.73          0     685.8          208.64          0          0          375.72               0               0
    19     4/4/2010     2906.66          91.44     0          418.98          0          0          279               0               0
    3     4/4/2010     1917.55          0     22.45          376.86          0          17.5          297.6               0               0
    2     4/4/2010     1470.66          22.45     0          365.8          0          8.75          178.56               0               0
    where each element/categpry sold by a store has 3 pieces of data: category cost, inventory of start of category, category shipping and handling

    Hello

    Something like that?

    SQL> select storenbr,max(case description when'chicken' then CAT_COST end) chicken,
      2      max(case description   when 'chicken' then CAT_IN   end) chicken_in,
      3      max(case description    when 'chicken' then "cat_s&h"    end) "chicken_S&H",
      4      max(case description when 'filets'  then CAT_COST end) filets,
      5      max(case description   when 'filets'  then CAT_IN end) filets_in,
      6      max(case description    when 'filets'  then "cat_s&h" end) "filets_S&H",
      7      max(case description when 'popcorn_chicken' then CAT_COST end) popcorn_chicken,
      8      max(case description   when 'popcorn_chicken' then CAT_IN   end) popcorn_chicken_in,
      9      max(case description    when 'popcorn_chicken' then "cat_s&h"    end) "popcorn_chicken_S&H"
    
     10  from dummy_data
     11  group by storenbr
     12  order by storenbr desc;
    
    STOR    CHICKEN CHICKEN_IN chicken_S&H     FILETS  FILETS_IN filets_S&H POPCORN_CHICKEN POPCORN_CHICKEN_
    ---- ---------- ---------- ----------- ---------- ---------- ---------- --------------- ------------
    0043    1113.78          0      688.65      482.2          0          0          238.08                  0              0
    0019    3388.93     238.73           0     770.53      28.28          0          327.36               74.4         0
    0003    2064.38     117.96           0        494          0          0           297.6                  0                0
    0002    1450.34          0           0      357.2          0          0           204.6                  0                  0  
    

    Twinkle

  • identifier is too long: expdp filtering using QUERY off TABLES =.

    All,

    I run large expdp work using a .bat file.  An example of one of the lines is the following:

    expdp directory "" / as sysdba "" = IMPORT_DB dumpfile=vismag_brightness%%U.dmp logfile = vismag_brightness.log ALL TABLES = sat_cat_owner.vismag_brightness QUERY = sat_cat_owner.vismag_brightness = compression:'------"where exists (" select visual_magnitude_uuid in the sat_cat_owner.visual_magnitude where sat_cat_owner.visual_magnitude.visual_magnitude_uuid=sat_cat_owner.vismag_brightness.visual_magnitude_uuid)\ "')"

    Present the results of .bat to this:

    OracleExportDataPumpIssues.png

    I then tried to put it in a settings file.  As always, you can see in the picture above, he already gave me an error, but I corrected which and he always gave me the same error.  The application was the same as above, only had no slashes return of evasion.

    Now this is why I am sure that I am right escape.  Now, I just need to find the reason for the identifier is too long.

    Here's a picture showing other odd behavior, trying to simplify the query to see if its because the query is too long.  AND if it is because its too long..how for I can config so it can handle?

    OracleSimpler.png

    The difference in the image above, is that the first test has only \"...while the second is what worked for me before top (if I try without the single quotes, it fails on citing the issue for the important query).  So the second cmd, as I have said, has "\" instead of just \"...and it does not work!"  When he did above for the larger request, but it gives error separated.

    Help, please!  Thank you

    Hello

    Try this instead

    Query ='sat_cat_owner.vismag_brightness: "Where exists (select visual_magnitude_uuid from the sat_cat_owner.visual_magnitude where sat_cat_owner.visual_magnitude.visual_magnitude_uuid = ku$ .visual_magnitude_uuid)" "

    Ku$ is an alias of special for the object currently being extraction - I think that in case you want to use exists, you must use this syntax - give it a try and see what happens.

    Other than that can replace you an IN clause instead?

    See you soon,.

    Rich

  • A query containing a subquery and Group By all-in-one

    Hi people,
    Any interesting fact but nerve racking situation I have here. I have a question that I have to do counts and amounts and I also need to have a Sub inside query. When I run my application, I get an error like this:

    Error in the command line column: 4:36
    Error report:
    SQL error: ORA-00979: not a GROUP BY expression
    00979 00000 - "not a GROUP BY expression"
    * Cause:
    * Action:

    Here's my query:
    select distinct to_char(c.start_date,'YYYY') start_date,
             substr(acc.account_num,1,12) account_number,
           ( select acc2.account_desc from student_account  acc2
             where  acc2.account_num = acc.account_num 
             and    acc2.account_type = 'A'
           ),
           COUNT(distinct(s.student_id))
    from student s,
           student_account acc,
           course   c
    where s.course_id = c.course_id
    and     s.account_num = acc.account_num
    and    to_char(c.start_date, 'YYYY/MM/DD') between '2004/01/01' and '2009/12/31'
    group by to_char(c.start_date,'YYYY'), substr(acc.account_num,1,12)
    order by 1;
    If I replace it with the acc.account_num (subquery) with a number that is in the database, then my request works well.

    Published by: Roxyrollers on March 29, 2011 16:45

    Hello

    We don't know what you want. It would really help if you posted some examples of data (CREATE TABLE and INSERT statements) and the results desired from these data.

    Are you sure that the scalar subquery will return ever more than one line? If so, you can wrap in a MIN or MAX aggregate function, as I've suggested before:

     select distinct to_char(c.start_date,'YYYY') start_date,
             substr(acc.account_num,1,12) account_number,
       MIN ( ( select acc2.account_desc from student_account  acc2     -- Changed
             where  acc2.account_num = acc.account_num
             and    acc2.account_type = 'A'
           ) ),                                   -- Changed
           COUNT(distinct(s.student_id))
    from student s,
           student_account acc,
           course   c
    where s.course_id = c.course_id
    and     s.account_num = acc.account_num
    and    to_char(c.start_date, 'YYYY/MM/DD') between '2004/01/01' and '2009/12/31'
    group by to_char(c.start_date,'YYYY'), substr(acc.acct_acc_num,1,12)
    order by 1;
    

    It seems that you could also simplify the query and make more fast, eliminating the scalar subquery. The table there is already part of the main query, you can do something like this:

    SELECT    TO_CHAR (c.start_date, 'YYYY')     AS start_date
    ,         SUBSTR (acc.account_num, 1, 12)      AS account_number
    ,       MIN ( CASE
                        WHEN  acc.account_type = 'A'
                  THEN  account_desc
                    END
               )                         AS a_desc
    ,         COUNT (DISTINCT s.student_id)          AS student_id_cnt
    FROM       student            s
    ,       student_account     acc
    ,       course          c
    WHERE       s.course_id          = c.course_id
    AND       s.account_num          = acc.account_num
    AND       c.start_date          BETWEEN DATE '2004-01-01'
                          AND     DATE '2009-12-31'
    GROUP BY  TO_CHAR (c.start_date, 'YYYY')
    ,            SUBSTR (acc.acct_acc_num, 1, 12)
    ORDER BY  start_date;
    

    I guess that course.start_date is a DATE. Instead of converting each start_date to string (so you can see if it is in the right range), it is more efficient and less prone to error, compared to other DATEs, as shown above.

    It is very strange that you

    substr(acc.account_num,1,12)
    

    in the select clause, but

    substr(acc.acct_acc_num,1,12)
    

    in the GROUP BY clause. Did you mean having the same column in both places?

    Yet once, without seeing some examples of data (CREATE TABLE and INSERT statements) and the results desired from this data, I can't do much.

  • Group Query Help

    Oracle 10G version | R/2

    This is a Customers table and we will have to find they are elgible for product produced B or both or none.

    But if you're serviceble by product B, it is certain that you will be good product a. (imagine the product A is greater coverage of Prouct and be produced is the smallest)

    What I have done becomes the product of A B and get the remains that are usable for the product and not product B.

    < pre >
    CREATE TABLE CUST_TEST
    (
    Number of cust_id,
    Column_serviceable_A varchar2 (2),
    Column_Serviceable_B varchar2 (2),
    Column_Color_A varchar2 (2),
    Column_Color_B varchar2 (2),
    Area_OO varchar2 (2),
    Area_H varchar2 (2),
    Varchar2 (10) STATE
    );

    insert into cust_test (Cust_ID, Column_serviceable_A, Column_Serviceable_B, Column_Color_A, Column_Color_B, Area_OO, Area_H, STATE)
    values(1,'Y','Y','G','G','Y','Y','HYD');

    insert into cust_test (Cust_ID, Column_serviceable_A, Column_Serviceable_B, Column_Color_A, Column_Color_B, Area_OO, Area_H, STATE)
    values(2,'Y','Y','G','G','Y','Y','HYD');

    insert into cust_test (Cust_ID, Column_serviceable_A, Column_Serviceable_B, Column_Color_A, Column_Color_B, Area_OO, Area_H, STATE)
    values(3,'Y',,'G',,'Y','Y','HYD');

    insert into cust_test (Cust_ID, Column_serviceable_A, Column_Serviceable_B, Column_Color_A, Column_Color_B, Area_OO, Area_H, STATE)
    values(4,'Y',,'R',,'Y','Y','BANG');

    insert into cust_test (Cust_ID, Column_serviceable_A, Column_Serviceable_B, Column_Color_A, Column_Color_B, Area_OO, Area_H, STATE)
    values(5,,,,,'Y','Y','BANG');

    insert into cust_test (Cust_ID, Column_serviceable_A, Column_Serviceable_B, Column_Color_A, Column_Color_B, Area_OO, Area_H, STATE)
    values(6,'Y','Y','G','G','Y','Y','CHEN');

    insert into cust_test (Cust_ID, Column_serviceable_A, Column_Serviceable_B, Column_Color_A, Column_Color_B, Area_OO, Area_H, STATE)
    values(7,'Y',,'G',,'Y','Y','CHEN');

    insert into cust_test (Cust_ID, Column_serviceable_A, Column_Serviceable_B, Column_Color_A, Column_Color_B, Area_OO, Area_H, STATE)
    values(8,'Y',,'G',,'Y','Y','CHEN');
    < / pre >

    < pre >
    Select
    (
    (
    Select sum (case when area_oo = 'Y' or area_h = 'Y' then 1 else 0 end) of CUST_TEST one
    where column_serviceable_A = 'Y '.
    and Column_Color_A ('g', 'A')
    and status = 'HYD.
    )
    -
    (
    Select sum (case when area_oo = 'Y' or area_h = 'Y' then 1 else 0 end) of CUST_TEST one
    where Column_Serviceable_B = 'Y '.
    and Column_Color_B ('g', 'A')
    and status = 'HYD.
    )
    )
    Double;
    < / pre >


    But I need this 15 times as there are 15 States, I want to do in a single request via the Group of. CUST_TESTis also a view and each query takes once NGOs as customers there 15 million.

    Please let me know if you need more information.

    Desirable output;

    COUNT (*) STATE
    HYD 1
    BANG null
    CHEN 2

    Thank you and best regards,
    Cracky

    Published by: CrackerJack 22 November 2010 16:51

    Hello

    Thanks for posting the sample data in a useful form. That really helps.

    So you want a query that produces a line of output for each value in the column state.
    That's exactly what "State GROUP BY" don't:

    SELECT       state
    ,       COUNT ( CASE
                      WHEN  column_serviceable_a  = 'Y'
                    AND   column_color_a         IN ('G', 'A')
                    THEN  1
                  END
                )
         - COUNT ( CASE
                      WHEN  column_serviceable_b  = 'Y'
                    AND   column_color_b         IN ('G', 'A')
                    THEN  1
                  END
                )     AS cnt
    FROM       cust_test
    WHERE       area_oo     = 'Y'
    AND       area_h     = 'Y'
    GROUP BY  state
    ORDER BY  state
    ;
    

    In fact, this becomes 0 as the county when no line meets the criteria of "has".
    If you prefer that NULL, as you posted, then replace the first indictment by AMOUNT:

    SELECT       state
    ,       SUM   ( CASE
                      WHEN  column_serviceable_a  = 'Y'
                    AND   column_color_a         IN ('G', 'A')
                    THEN  1
                  END
                )
         - COUNT ( CASE
                      WHEN  column_serviceable_b  = 'Y'
                    AND   column_color_b         IN ('G', 'A')
                    THEN  1
                  END
                )     AS cnt
    FROM       cust_test
    WHERE       area_oo     = 'Y'
    AND       area_h     = 'Y'
    GROUP BY  state
    ORDER BY  state
    ;
    

    Output:

    STATE             CNT
    ---------- ----------
    BANG
    CHEN                2
    HYD                 1
    

    Note that we do not need duplicate in this problem. Whenever you are tempted to use double, ask yourself why. See if the information you want to be taken from another table that you use when even.

    This should be much faster than the original request. Instead of making 2 passes through the table for each status value (2 * 15 = 30 past total), just make a pass through the table.

    Published by: Frank Kulash, 22 November 2010 20:14
    Simplified 2nd query (for number of NULL).

  • Retrieving values from XML in Oracle 9i

    Hello

    I have the following XML:

    <? XML version = "1.0" encoding = "UTF-8"? >

    " < GenericRequest xmlns =" http://webservices.mysite.com/test "xmlns:ns =" " http://webservices.mysite.com/test "xmlns:ns1 =" " http://webservices.mysite.com/test "xmlns:ns2 =" " http://webservices.mysite.com/test ">

    < ns1:order >

    < ns1:orderItems >

    < ns1:orderItem >

    create < ns1:operation > < / ns1:operation >

    < ns1:brickId > TST123 < / ns1:brickId >

    < ns1:brickAttributes >

    < ns1:attribute >

    < ns2:name > COUNTRY < / ns2:name >

    < ns2: value > U.S. < / ns2: value >

    < / ns1:attribute >

    < ns1:attribute >

    < ns2:name > CUST_ID < / ns2:name >

    < ns2: value > 12345 < / ns2: value >

    < / ns1:attribute >

    < ns1:attribute >

    < ns2:name > CITY < / ns2:name >

    < ns2: value > New York < / ns2: value >

    < / ns1:attribute >

    < / ns1:brickAttributes >

    < / ns1:orderItem >

    < / ns1:orderItems >

    < / ns1:order >

    < / GenericRequest >

    And I use an older version of Oracle (it's something I can't change unfortunately):

    SELECT * FROM version of v$.

    BANNER

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

    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64 bit Production

    PL/SQL Release 9.2.0.8.0 - Production
    CORE Production 9.2.0.8.0
    AMT for HP - UX: 9.2.0.8.0 - Production Version
    NLSRTL Version 9.2.0.8.0 - Production

    What is the best way to get the list name / value in a format like this with a SQL query?

    VALUE NAME

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

    COUNTRIES WE

    CUST_ID 12345

    New York CITY

    Kind regards.

    Alberto

    Hello Alberto,.

    You can do it like this:

    with sample_data as)

    Select xmltype)

    '

    "http://WebServices.mysite.com/test" xmlns:ns ="http://webservices.mysite.com/test" xmlns:ns1 ="http://webservices.mysite.com/test" xmlns:ns2 = "http://webservices.mysite.com/test" >. "

    create

    TST123

    COUNTRY

    WE

    CUST_ID

    12345

    CITY

    New York City

    xmlDoc ')

    of the double

    )

    Select extractvalue (value (x), ' / ns1:attribute / ns2:name ',' xmlns:ns1 is "http://webservices.mysite.com/test", xmlns:ns2 ="http://webservices.mysite.com/test" "" ") as the name

    ExtractValue (value (x), ' / ns1:attribute / ns2: value ',' xmlns:ns1 = "http://webservices.mysite.com/test", xmlns:ns2 ="http://webservices.mysite.com/test" "" ") as the value

    of sample_data t

    table)

    xmlsequence)

    extract)

    t.xmlDoc

    , ' / GenericRequest / ns1:order / ns1:orderItems / ns1:orderItem / ns1:brickAttributes / ns1:attribute'

    ", ' xmlns ="http://webservices.mysite.com/test", xmlns:ns1 ="http://webservices.mysite.com/test"". "

    )

    )

    ) x

    ;

    Namespace URI appear to be the same in your example of XML, if this is really the case, you can simplify the query and use the same namespace by default in any of the query.

  • CONNECT BY giving different results / duplicate records

    I have a hierarchy like this:

    UserTable-> username, treename_code

    username treename_code

    Scott TREE

    Henry TREE

    TREENAMES-> treename_code

    treename_code

    TREE

    subtree-> id, parent_id, treename_code

    ID parent_id treename_code

    1 null TREE

    2 1 TREE

    select case when connect_by_isleaf = 1 then 0
                when level = 1             then 1
                else                           -1
           end as status, 
           level, 
           subtree.id as value, 
           SYS_CONNECT_BY_PATH(subtree.id, '/') Path
      from usertable,
           treenames,
           subtree
      where upper(usertable.username)=upper(:username)
        and treenames.treename_code=usertable.treename_code
        and subtree.treename_code=treenames.treename_code
      start with subtree.parent_id is null
      connect by subtree.parent_id=prior subtree.id;
    
    

    Database version: 11.2.0.1.0

    According to the user, the order of results is different: we give values:

    1-2-2 (double on '2')

    gives another

    2 1-2 (always double on '2')

    BUT on another database, same version, it gives:

    1-2 (which is expected)

    Any idea?

    This is essentially because of the what the predicate to filter for the USER name is applied. If you are using an Inline view, you will get the desired result.

    Check this. I just simplified your query by removing just the other columns in the select list. But the CONNECT BY and are of the join of the table intact.

    SQL > select subtree.id
    2 usertable,
    3 treenames,
    subtree 4
    5 where upper (usertable.username) = upper ('scott')
    6 and treenames.treename_code = usertable.treename_code
    7 and subtree.treename_code = treenames.treename_code
    8 start
    9 with subtree.parent_id is null
    10 connect
    11 by prior subtree.id = subtree.parent_id;

    ID
    ----------
    2
    1
    2

    SQL > select * from table (dbms_xplan.display_cursor);

    PLAN_TABLE_OUTPUT
    -------------------------------------------------------------------------------------------------
    ----------------------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    ----------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |           |       |       |     7 (100) |          |
    |*  1 |  FILTER |           |       |       |            |          |
    |*  2 |   CONNECT BY WITH FILTERING |           |       |       |            |          |
    |*  3 |    HASH JOIN |           |     2.   102.     7 (15) | 00:00:01 |
    |   4.     THE CARTESIAN MERGE JOIN.           |     2.    90.     4 (0) | 00:00:01 |
    |*  5 |      TABLE ACCESS FULL | SUBTREE.     1.    32.     2 (0) | 00:00:01 |
    |   8 2 SORT OF BUFFER.           |     2.    26.     2 (0) | 00:00:01 |
    |   7.       TABLE ACCESS FULL | USERTABLE |     2.    26.     2 (0) | 00:00:01 |
    |   3 ×     TABLE ACCESS FULL | TREENAMES |     1.     8-2-2 (0) | 00:00:01 |
    |*  9 |    HASH JOIN |           |     1.    51.     7 (15) | 00:00:01 |
    |  10.     THE CARTESIAN MERGE JOIN.           |     1.    45.     4 (0) | 00:00:01 |
    | * 11 |      HASH JOIN |           |       |       |            |          |
    |  12.       CONNECT PUMP |           |       |       |            |          |
    |  13.       TABLE ACCESS FULL | SUBTREE.     1.    32.     2 (0) | 00:00:01 |
    |  14.      KIND OF BUFFER.           |     2.    26.     2 (0) | 00:00:01 |
    |  15.       TABLE ACCESS FULL | USERTABLE |     2.    26.     2 (0) | 00:00:01 |
    |  16.     TABLE ACCESS FULL | TREENAMES |     1.     6.     2 (0) | 00:00:01 |
    ----------------------------------------------------------------------------------------

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

    1 Filter (SUPERIOR ("USERTABLE".) "USER NAME") = "SCOTT") "
    2 - access("SUBTREE".") PARENT_ID "= NULL PREREQUISITE)
    3 - access("TREENAMES".") TREENAME_CODE '=' USERTABLE '. "" TREENAME_CODE "AND
    "SUBTREE". "" TREENAME_CODE "=" TREENAMES. " ("' TREENAME_CODE")
    5 - filter("SUBTREE".") (PARENT_ID' IS NULL)
    9 - access("TREENAMES".") TREENAME_CODE '=' USERTABLE '. "" TREENAME_CODE "AND
    "SUBTREE". "" TREENAME_CODE "=" TREENAMES. " ("' TREENAME_CODE")
    11 - access("SUBTREE".") PARENT_ID "= NULL PREREQUISITE)

    If you see that the filter for the USER name is applied after that CONNECT BY runs. But if I use a view online. then check it

    SQL > select id
    2 starting at)
    3. Select subtree.id
    4, subtree.parent_id
    5 usertable,
    6 treenames,
    subtree 7
    8 where upper (usertable.username) = upper ('scott')
    9 and treenames.treename_code = usertable.treename_code
    10 and subtree.treename_code = treenames.treename_code
    11          )
    Starter 12
    13 with parent_id is null
    14 connect
    15 by parent_id = prior id;

    ID
    ----------
    1
    2

    SQL > select * from table (dbms_xplan.display_cursor);

    PLAN_TABLE_OUTPUT
    -------------------------------------------------------------------------------------------------
    ---------------------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    ---------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |           |       |       |     7 (100) |          |
    |*  1 |  CONNECT BY WITH FILTERING |           |       |       |            |          |
    |*  2 |   HASH JOIN |           |     1.    51.     7 (15) | 00:00:01 |
    |   3.    THE CARTESIAN MERGE JOIN.           |     1.    45.     4 (0) | 00:00:01 |
    |*  4 |     TABLE ACCESS FULL | USERTABLE |     1.    13.     2 (0) | 00:00:01 |
    |   5.     KIND OF BUFFER.           |     1.    32.     2 (0) | 00:00:01 |
    |*  6 |      TABLE ACCESS FULL | SUBTREE.     1.    32.     2 (0) | 00:00:01 |
    |   7.    TABLE ACCESS FULL | TREENAMES |     1.     6.     2 (0) | 00:00:01 |
    |*  8 |   HASH JOIN |           |     1.    51.     7 (15) | 00:00:01 |
    |   9.    THE CARTESIAN MERGE JOIN.           |     1.    45.     4 (0) | 00:00:01 |
    | * 10 |     HASH JOIN |           |       |       |            |          |
    |  11.      CONNECT PUMP |           |       |       |            |          |
    |  12.      TABLE ACCESS FULL | SUBTREE.     1.    32.     2 (0) | 00:00:01 |
    |  13.     KIND OF BUFFER.           |     1.    13.     2 (0) | 00:00:01 |
    | * 14 |      TABLE ACCESS FULL | USERTABLE |     1.    13.     2 (0) | 00:00:01 |
    |  15.    TABLE ACCESS FULL | TREENAMES |     1.     6.     2 (0) | 00:00:01 |
    ---------------------------------------------------------------------------------------

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

    1 - access("SUBTREE".") PARENT_ID "= NULL PREREQUISITE)
    2 - access("TREENAMES".") TREENAME_CODE '=' USERTABLE '. "" TREENAME_CODE "AND
    "SUBTREE". "" TREENAME_CODE "=" TREENAMES. " ("' TREENAME_CODE")
    4 filter (SUPERIOR ("USERTABLE".) "USER NAME") = "SCOTT") "
    6 - filter("SUBTREE".") (PARENT_ID' IS NULL)
    8 - access("TREENAMES".") TREENAME_CODE '=' USERTABLE '. "" TREENAME_CODE "AND
    "SUBTREE". "" TREENAME_CODE "=" TREENAMES. " ("' TREENAME_CODE")
    10 - access("SUBTREE".") PARENT_ID "= NULL PREREQUISITE)
    14 filter (SUPERIOR ("USERTABLE".) "USER NAME") = "SCOTT") "

    Here, the filter is applied before CONNECT you IS executed. This is the reason why you get the unexpected result in your query. Use the online mode.

  • order of XmlAttribute

    Hi, im sure that someone probably will this quickly.

    IM generate xml in oracle, one of the nested queries is similar to this...
    select  test1 
              ,test2
               ,  xmlelement
                    ( "QUESTION"
                    , xmlattributes ( question_n as "question_number",question as "question_t")  
                  
                 
                    ) AS Xt1 
            FROM  myview_VW  
    but for some reason any in my dissertation to result the order of the questions are always messed up, is there a way to keep the order of attribute?


    I tried an order around here, but this query is nested in many others. as I said, that basically, I just want to keep the order.
    select  test1 
              ,test2
               ,  xmlelement
                    ( "QUESTION"
                    , xmlattributes ( question_n as "question_number",question as "question_t")  
                  
                 
                    ) AS Xt1 order by question_n
            FROM  myview_VW  
    I know that I do not understand any of the construction code, if necessary, I'll

    Thank you

    Jay wrote:
    Thanks BluShadow - but that removed a whole level which I can't do.

    Why? Put a different output?
    In your example, LEVEL1 and LEVEL2 can be combined in a single subquery, this is what BluShadow done to simplify the query and then apply the command without having to go QUESTION_NUMBER to the next level.

    If she asks problem in your real cases, keep the levels they are now and just add the ORDER BY clause if necessary.
    If you choose to do, you go QUESTION_NUMBER level 1 or 2:

    ...
    level_1  as
    (select  top1
               ,  top2
               ,  dt
               ,  question_number
                    ,  xmlelement
                    ( "QUESTION"
                    , xmlattributes ( question_number as "question_number",question as "question_text" )
                                ) AS X1
            FROM  vtesting
        ) 
    
        , LEVEL_2  AS
        ( select  top1,top2,dt
               ,  Xmlelement
                    ( "SURVEY"
                    , xmlattributes ( dt as "date"
                    )
                    , xmlagg ( x1   ORDER BY to_number(question_number))
                    ) as x2
            FROM  LEVEL_1
           GROUP  BY  top1,top2,dt
        )
    ...
    
  • Error copying data in Planning

    Hi all

    We are on Hyperion Planning 11.1.1.3 and we try to copy the data inside the planning application which also includes support details'. It gives the following error. Has anyone seen this problem? When I have some research, microsoft has released a fix but we do not know how this hotfix will impact.
    Any suggestions are welcome.

    Error
    MSG_COPY_DATA_OPTIONS_FAILED: [Hyperion] [SQLServer JDBC Driver] [SQL Server] the query processor ran out of internal resources and could not produce a query plan. It is an event that is rare and only intended for extremely complex queries or queries that refer to a very large number of tables or partitions. Please simplify the query. If you believe that you have received this message in error, contact customer care for more information.

    Have a read of the document following on Support of Oracle - error "MSG_COPY_DATA_OPTIONS_FAILED" when performing data Copy of planning [1401758.1 ID] function

    See you soon

    John
    http://John-Goodwin.blogspot.com/

Maybe you are looking for