order by with rownum

Hi Hello all please help me I want to choose folder 100 100000 record Albums, but my answer to the query is too slow. Please give me an idea to improve this issue.

Select *.

from (SELECT *)

of dhcpactivitylogs

WHERE CREATEDDATE BETWEEN

18 NOVEMBER 14 1.00.00 AM'

AND

21 NOVEMBER 14 12.00.00 PM'

dhcpactivitylogsid desc order)

where rownum < = 100;

If im using simple rownum works it random return 100 and I need top 100.

If there are indexes on (DHCPACTIVITYLOGSID, CREATEDDATE) and the query is changed, a little bit like below, you should see "stop key" somewhere in the plan which comes only 100 lines in the order of the index.

Select *.

from (SELECT t.*, rownum rn

of dhcpactivitylogs t

WHERE CREATEDDATE BETWEEN

18 NOVEMBER 14 1.00.00 AM'

AND

21 NOVEMBER 14 12.00.00 PM'

dhcpactivitylogsid desc order)

-where rownum<=>

where rn<=>

Tags: Database

Similar Questions

  • ORDER BY with ROWNUM in the selection list

    Hello

    I have the query as the bellows for Oracle 11 g:

    create the table em_c (int vl_s_ec, int id_em_em, int id_empcre_ecr, int id_em_ec);

    create em table (int id_em_em)

    Select e.id_em_em
    NVL)
    (SELECT * FROM (SELECT a.vl_s_ec FROM em_c a WHERE a.id_em_em = ec.id_em_em))
    AND a.id_empcre_ecr < ec.id_em_ec order of a.id_em_ec DESC) WHERE ROWNUM < = 1), 0) AS col2
    Of em_c ec
    INNER JOIN em e on ec.id_em_em = e.id_em_em
    WHERE 1 = 1;

    But internal subselect doesn't see table "em_c ec" of outer FROM clause. This is why the following error occurs:

    SQL error: ORA-00904: "EC". "" ID_EM_EC ": invalid identifier

    Please, help me to make it work.

    Published by: user11290901 on December 17, 2010 02:11
    SELECT  e.id_em_em,
            (
             SELECT  nvl(max(a.vl_s_ec) KEEP(DENSE_RANK LAST ORDER BY a.id_em_ec),0)
               FROM  em_c a
               WHERE a.id_em_em = ec.id_em_em
            ) AS col2
      FROM  em_c ec
      INNER JOIN em e on ec.id_em_em = e.id_em_em
      WHERE 1 = 1
    /
    

    SY.

  • order by with analytic function

    Hi gurus

    Need your help again.

    I have the following data.

    Examples of data

    Select * from

    (

    As with a reference

    (

    Select ' 100 ', ' 25' grp lb, to_date('2012-03-31') ter_dt, 'ABC' package_name FROM DUAL union all

    Select ' 100 ', ' 19', to_date ('2012-03-31'), 'AA' OF the whole union DOUBLE

    Select ' 200 ', ' 25', to_date('2012-03-31'), 'CC' FROM DUAL union all

    Select ' 300 ', ' 28', to_date('2012-03-31'), 'XX' from DUAL union all

    Select ' 300 ', ' 28', to_date('4444-12-31'), 'XY' from DUAL

    )

    Select the grp, lb, ter_dt, Package_name

    ROW_NUMBER() over (partition by order of grp by case when lb = '19' then 1)

    When lb = '25' then 2

    ro_nbr end)

    Reference)

    -where ro_nbr = 1

    ;

    -----------

    The query above returns the following result:

    Existing query result

    GRP LB TER_DT package_name RO_NBR

    1001903/12/31AA1
    1002503/12/31ABC2
    2002503/12/31CC1
    3002803/12/31XX1
    3002844 12-31XY2

    If you can see the data above then I use the order clause with function row_number analytic and prioritize data according to LB using the order by clause.

    Now the problem is I need simple stored against each group so I write the following query:

    Query

    Select * from

    (

    As with a reference

    (

    Select ' 100 ', ' 25' grp lb, to_date('2012-03-31') ter_dt, 'ABC' package_name FROM DUAL union all

    Select ' 100 ', ' 19', to_date ('2012-03-31'), 'AA' OF the whole union DOUBLE

    Select ' 200 ', ' 25', to_date('2012-03-31'), 'CC' FROM DUAL union all

    Select ' 300 ', ' 28', to_date('2012-03-31'), 'XX' from DUAL union all

    Select ' 300 ', ' 28', to_date('4444-12-31'), 'XY' from DUAL

    )

    Select the grp, lb, ter_dt, Package_name

    ROW_NUMBER() over (partition by order of grp by case when lb = '19' then 1)

    When lb = '25' then 2

    ro_nbr end)

    Reference)

    where ro_nbr = 1

    ;

    The query result

    GRP LB TER_DT RO_NBR

    1001903/12/31AA1
    2002503/12/31CC1
    3002803/12/31XX1

    My required result is that 300 GRP contains 2 folders and I need the record with the latest means of ter_dt and right now, I only get the latest.

    My output required

    GRP LB TER_DT RO_NBR

    1001903/12/31AA1
    2002503/12/31CC1
    3002844 12-31XY1

    Please guide. Thank you

    Hello

    The query you posted is the ro_nbr assignment based on nothing other than lb.  When there are 2 or more lines that have an equal claim to get assigned ro_nbr = 1, then one of them is chosen arbitrarily.  If, when a tie like that occurs, you want the number 1 to be assigned based on some sort, and add another expression of Analytics ORDER BY clause, like this:

    WITH got_ro_nbr AS

    (

    SELECT the grp, lb, ter_dt, nom_package

    ROW_NUMBER () OVER (PARTITION BY grp

    ORDER OF CASES

    WHEN lb = '19' THEN 1

    WHEN lb = '25' THEN 2

    END

    , ter_dt DESC-* NEW *.

    ) AS ro_nbr

    REFERENCE

    )

    SELECT the grp, lb, ter_dt, nom_package

    OF got_ro_nbr

    WHERE ro_nbr = 1

    ;

  • Subselect with Rownum and Order By

    Good morning, people, I'm trying to do some Firebird SQL work in Oracle and there is something that I can't find an easy way to deal with:

    CUSTOMER has many RECIPES, let's say I want the ID of the last receipt of a customer...

    That's how it's done in FB:

    SELECT

    c.ID, c.name,

    (SELECT FIRST r.id 1

    RECEPTION r

    WHERE r.customer_id = c.id

    ORDER BY r.creation_date DESC) as LAST_RECEIPT_ID

    CUSTOMER c

    It's simple and works like a charm... the subselect statement will order first of all, the most recent reception will be the first line, then I use to avoid any error 'select several lines in singleton' a 'first 1 ", equivalent to rownum = 1;

    If I try this with Oracle it won't work:

    SELECT

    c.ID, c.name,

    (SELECT r.id

    RECEPTION r

    WHERE r.customer_id = c.id

    AND rownum = 1

    ORDER BY r.creation_date DESC) as LAST_RECEIPT_ID

    CUSTOMER c


    What is the best way to achieve the same in Oracle?

    SELECT c.id
    ,      c.name
    ,      (SELECT MAX(r.id) KEEP (DENSE_RANK FIRST ORDER BY r.creation_date DESC) last_receipt_id
            FROM   receipt r
            WHERE  r.customer_id = c.id) as last_receipt_id
    FROM customer c;
    
  • How to order by working with rownum

    Oracle worm: 11g

    Hi all
    I have 2 cases here, with external control by one and another without external by command.
    I see no difference in the results for the moment.
    Case 1:
    /* Formatted on 4/30/2013 2:12:28 PM (QP5 v5.240.12305.39446) */
    SELECT *
      FROM (  SELECT ROWNUM rn, id
                FROM (SELECT 9 AS id FROM DUAL
                      UNION ALL
                      SELECT 1 FROM DUAL
                      UNION ALL
                      SELECT 14 FROM DUAL
                      UNION ALL
                      SELECT 7 FROM DUAL
                      UNION ALL
                      SELECT 5 FROM DUAL
                      UNION ALL
                      SELECT 6 FROM DUAL
                      UNION ALL
                      SELECT 13 FROM DUAL
                      UNION ALL
                      SELECT 8 FROM DUAL
                      UNION ALL
                      SELECT 2 FROM DUAL
                      UNION ALL
                      SELECT 4 FROM DUAL
                      UNION ALL
                      SELECT 19 FROM DUAL
                      UNION ALL
                      SELECT 3 FROM DUAL)
            ORDER BY id)
     WHERE rn BETWEEN 1 AND 6;
     
    Case 2:
    I added the command by external clause in this case
    But I want to make sure if I really need to have the order of outer query by here.
    /* Formatted on 4/30/2013 2:12:28 PM (QP5 v5.240.12305.39446) */
    SELECT *
      FROM (  SELECT ROWNUM rn, id
                FROM (SELECT 9 AS id FROM DUAL
                      UNION ALL
                      SELECT 1 FROM DUAL
                      UNION ALL
                      SELECT 14 FROM DUAL
                      UNION ALL
                      SELECT 7 FROM DUAL
                      UNION ALL
                      SELECT 5 FROM DUAL
                      UNION ALL
                      SELECT 6 FROM DUAL
                      UNION ALL
                      SELECT 13 FROM DUAL
                      UNION ALL
                      SELECT 8 FROM DUAL
                      UNION ALL
                      SELECT 2 FROM DUAL
                      UNION ALL
                      SELECT 4 FROM DUAL
                      UNION ALL
                      SELECT 19 FROM DUAL
                      UNION ALL
                      SELECT 3 FROM DUAL)
            ORDER BY id)
     WHERE rn BETWEEN 1 AND 6;
     ORDER BY id;
    Thank you
    Rod.

    Hey, Rod,

    SamFisher wrote:
    ... I see no difference in the results for the moment.

    You can not, but you are not sure that you will never see a difference. There may be a difference if you change versions, or if you add more data, or for no apparent reason.

    If there is an ORDER BY clause in the main query (as in query 2) then the output is guaranteed to be in that order.
    Is there no ORDER BY clause in the main query (as in the query 1), then there is no guarantee that the lines will be in a particular order. If Oracle finds it convenient to display rows in order by one of the columns (for example, rn) then she will do. You can't count on it always does the same thing, unless there is an ORDER BY clause.

    You should check the ROW_NUMBER analytic function. It is much more useful and easier to understand, as ROWNUM. (In this example, it maybe not simple, however.)

  • order by desc or ASC does not work with rownum

    SQL> desc offer
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     OFFER_ID                                  NOT NULL NUMBER(14)
     DOMAIN_ID                                          NUMBER(14)
     OFFERDATE                                          TIMESTAMP(0)
     CONTACTPERSON                                      VARCHAR2(36)
     EMAIL                                              VARCHAR2(50)
     TEL                                                VARCHAR2(23)
     CATEGORY                                           NUMBER(2)
     AMOUNT                                             NUMBER(5)
     STATUS                                             NUMBER(2)
    
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  select to_char(offerdate,'dd-Mon-yyyy'),
      2     offer_id,
      3     amount
      4  from
      5     offer
      6  where
      7     domain_id=1
      8     and amount is not null
      9* order by offerdate desc
    SQL> /
    
    TO_CHAR(OFF   OFFER_ID     AMOUNT
    ----------- ---------- ----------
    27-Apr-2010          4         55
    26-Apr-2010          5         45
    26-Apr-2010          3         50
    26-Apr-2010          2         45
    
    /*****These may be Ten thousand rows*****/
    When you add a'm rownum < 2 order by asc or desc in my query, then it does not work.
    SQL> ed
    Wrote file afiedt.buf
    
      1  select to_char(offerdate,'dd-Mon-yyyy'),
      2     offer_id,
      3     amount
      4  from
      5     offer
      6  where
      7     domain_id=1
      8     and amount is not null
      9  and
     10     rownum<2
     11* order by offerdate desc
    SQL> /
    
    TO_CHAR(OFF   OFFER_ID     AMOUNT
    ----------- ---------- ----------
    26-Apr-2010          5         45
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  select to_char(offerdate,'dd-Mon-yyyy'),
      2     offer_id,
      3     amount
      4  from
      5     offer
      6  where
      7     domain_id=1
      8     and amount is not null
      9  and
     10     rownum<2
     11* order by offerdate asc
    SQL> /
    
    TO_CHAR(OFF   OFFER_ID     AMOUNT
    ----------- ---------- ----------
    26-Apr-2010          5         45
    I just want to display a disc of DB offerDate wise

    Thank you in anticipation

    Try this

    select to_char(offerdate,'dd-Mon-yyyy'),
           offer_id,
           amount
        from(
        select to_char(offerdate,'dd-Mon-yyyy'),
           offer_id,
           amount
        from
    
           offer
        where
           domain_id=1
           and amount is not null
    
           order by offerdate asc)
    where  rownum<2
    

    Published by: user12984479 on April 27, 2010 04:34

  • SYS_CONNECT_BY_PATH with rownum vs rownumber for top - N query

    Oracle 9.2.0.8...

    Try to use the sys_connect_by_path to build a common thread of our hierarchy. Using the following query top - N, based on the implementation of Tom Kyte rather use rownumber or rownum, sys_connect_by_path returns null:
    SELECT *
      FROM (SELECT     /*+ FIRST_ROWS(25) */
                       score (1), cc.category_type_id, cc.content_category_id,
                       DECODE (:lang,
                               'EN', cc.content_category_name_en,
                               cc.content_category_name_fr
                              ) content_category_name,
                       SYS_CONNECT_BY_PATH
                          (DECODE (:lang,
                                   'EN', cc.content_category_name_en,
                                   cc.content_category_name_fr
                                  ),
                           ' \ '
                          ) content_bread_crumb,
                       TO_CHAR (GREATEST (cc.date_updated, cc.date_created),
                                'yyyy/mm/dd'
                               ) content_updated_date,
                       ROW_NUMBER () OVER (ORDER BY score (1) DESC) rn
                  FROM content_categories cc, CONTENTS c
                 WHERE cc.content_category_id = c.content_category_id
                   AND cc.category_type_id = 2
                   AND contains (c.top_html_content_en,
                                 '(("{employment}") AND (SYN({jobs},crt_thes)))',
                                 1
                                ) > 0
                   AND cc.approval_ind = 1
            CONNECT BY PRIOR cc.content_category_id =
                                                     cc.content_category_parent_id
            START WITH cc.content_category_parent_id IS NULL)
     WHERE rn BETWEEN 1 AND 25
    If I apply the same query, but use rownum instead of rownumber, sys_connect_by_path returns good breadcrumb:
    SELECT *
      FROM (SELECT     /*+ FIRST_ROWS(25) */
                       score (1), cc.category_type_id, cc.content_category_id,
                       DECODE (:lang,
                               'EN', cc.content_category_name_en,
                               cc.content_category_name_fr
                              ) content_category_name,
                       SYS_CONNECT_BY_PATH
                          (DECODE (:lang,
                                   'EN', cc.content_category_name_en,
                                   cc.content_category_name_fr
                                  ),
                           ' \ '
                          ) content_bread_crumb,
                       TO_CHAR (GREATEST (cc.date_updated, cc.date_created),
                                'yyyy/mm/dd'
                               ) content_updated_date
                  FROM content_categories cc, CONTENTS c
                 WHERE cc.content_category_id = c.content_category_id
                   AND cc.category_type_id = 2
                   AND contains (c.top_html_content_en,
                                 '(("{employment}") AND (SYN({jobs},crt_thes)))',
                                 1
                                ) > 0
                   AND cc.approval_ind = 1
            CONNECT BY PRIOR cc.content_category_id =
                                                     cc.content_category_parent_id
            START WITH cc.content_category_parent_id IS NULL order by score(1) DESC)
     WHERE rownum BETWEEN 1 AND 25
    Sys_connect_by_path will return for example:
    Toolbox, information employee expectations with respect, employees of call performance centers

    It seems that the first query executes better... base explain plan... so I prefer to use instead of rownum, but cannot if sys_connect_by_path fails

    Any ideas?

    pl_sequel wrote:

    Any ideas?

    Just a suggestion. Mixture of hierarchical query with analytical functions could be highly combustible :). For example, 10.2.0.4.0 & 11.1.0.6.0:

    select  sys_connect_by_path(ename,'/') path
      from  emp
      start with mgr is null
      connect by mgr = prior empno
    /
    
    PATH
    ----------------------------------------
    /KING
    /KING/JONES
    /KING/JONES/SCOTT
    /KING/JONES/SCOTT/ADAMS
    /KING/JONES/FORD
    /KING/JONES/FORD/SMITH
    /KING/BLAKE
    /KING/BLAKE/ALLEN
    /KING/BLAKE/WARD
    /KING/BLAKE/MARTIN
    /KING/BLAKE/TURNER
    
    PATH
    ----------------------------------------
    /KING/BLAKE/JAMES
    /KING/CLARK
    /KING/CLARK/MILLER
    
    14 rows selected.
    

    Now add ROW_NUMBER:

    SQL> select  sys_connect_by_path(ename,'/') path,
      2          row_number() over(order by sal) rn
      3    from  emp
      4    start with mgr is null
      5    connect by mgr = prior empno
      6  /
    
    PATH                                             RN
    ---------------------------------------- ----------
                                                      1
                                                      2
                                                      3
                                                      4
                                                      5
                                                      6
                                                      7
                                                      8
                                                      9
                                                     10
                                                     11
    
    PATH                                             RN
    ---------------------------------------- ----------
                                                     12
                                                     13
                                                     14
    
    14 rows selected.
    
    SQL> 
    

    Separates the analytical hierarchy part resolves the problem:

    select  path,
            row_number() over(order by sal) rn
      from  (
             select  sys_connect_by_path(ename,'/') path,
               sal
               from  emp
               start with mgr is null
               connect by mgr = prior empno
            )
    /
    
    PATH                                             RN
    ---------------------------------------- ----------
    /KING/JONES/FORD/SMITH                            1
    /KING/BLAKE/JAMES                                 2
    /KING/JONES/SCOTT/ADAMS                           3
    /KING/BLAKE/MARTIN                                4
    /KING/BLAKE/WARD                                  5
    /KING/CLARK/MILLER                                6
    /KING/BLAKE/TURNER                                7
    /KING/BLAKE/ALLEN                                 8
    /KING/CLARK                                       9
    /KING/BLAKE                                      10
    /KING/JONES                                      11
    
    PATH                                             RN
    ---------------------------------------- ----------
    /KING/JONES/SCOTT                                12
    /KING/JONES/FORD                                 13
    /KING                                            14
    
    14 rows selected.
    
    SQL>  
    

    SY.

  • SDO_RELATE within PL/SQL query with rownum clause runs slowly on 12 c - works great on 10 g

    Hello

    I use the database 12.1.0.2 with a node 2 RAC on Windows.

    I am struck by a really weird performance problem with a particular query.  Bear with me while I try to explain...

    I have a chart with lines 30 sdo_geometry million, in 7 partitions with a local partitioned spatial index divided.  Called BIG_PARTITIONED_TABLE for this example.

    I query the table to search for one line with a geometry that is equal to the geometry of my request.  In this case I use sdo_relate with "mask = equal".  Instantly returns:

    SQL> select id, geometry
      2  from       BIG_PARTITIONED_TABLE o
      3  where      sdo_relate(o.geometry, sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      4     SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272)), 'mask=equal') = 'TRUE'
      5  and rownum = 1;
    
            ID
    ----------
    GEOMETRY(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    -------------------------------------------------------------------------------
    2.5405E+12
    SDO_GEOMETRY(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272))
    
    Elapsed: 00:00:00.10
    
    

    But if I put the same query in PL/SQL, so it takes 21 seconds:

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_relate(o.geometry, l_window_geom, 'mask=equal') = 'TRUE'
    13     and rownum = 1;
    14
    15  end;
    16  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:21.13
    
    

    If I remove the "rownum = 1", then it returns instantly:

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_relate(o.geometry, l_window_geom, 'mask=equal') = 'TRUE';
    13
    14  end;
    15  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.03
    
    

    If using sdo_equal instead of sdo_relate and keep the "rownum = 1", then it returns instantly.

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_equal(o.geometry, l_window_geom) = 'TRUE'
    13     and rownum = 1;
    14
    15  end;
    16  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.13
    
    

    Here is a comparison of the plans to explain.  First, here's the good thing, that is using the spatial index (BIG_PARTITIONED_TABLE_SPIND):

    select id, GEOMETRY
    FROM
    BIG_PARTITIONED_TABLE O WHERE SDO_EQUAL(O.GEOMETRY, :B1 ) = 'TRUE'
    AND ROWNUM = 1
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.01       0.02          0         39          0           0
    Fetch        1      0.00       0.01          0         31          0           1
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        3      0.01       0.04          0         70          0           1
    
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 263     (recursive depth: 1)
    Number of plan statistics captured: 1
    
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
    ---------- ---------- ----------  ---------------------------------------------------
             1          1          1  COUNT STOPKEY (cr=99 pr=0 pw=0 time=43307 us)
             1          1          1   PARTITION RANGE ALL PARTITION: 1 7 (cr=99 pr=0 pw=0 time=43297 us cost=0 size=66 card=1)
             1          1          1    TABLE ACCESS BY LOCAL INDEX ROWID BIG_PARTITIONED_TABLE PARTITION: 1 7 (cr=99 pr=0 pw=0 time=43280 us cost=0 size=66 card=1)
             1          1          1     DOMAIN INDEX  BIG_PARTITIONED_TABLE_SPIND (cr=98 pr=0 pw=0 time=43250 us)
    
    

    Then the slow that does not use the spatial index.

    select id, GEOMETRY
    FROM
    BIG_PARTITIONED_TABLE O WHERE SDO_RELATE(O.GEOMETRY, :B1 , 'mask=equal') = 'TRUE'
      AND ROWNUM = 1
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.03       0.03          0       1123          0           0
    Fetch        1     24.25      24.25          0     499429          0           1
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        3     24.30      24.29          0     500552          0           1
    
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 263     (recursive depth: 1)
    Number of plan statistics captured: 1
    
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
    ---------- ---------- ----------  ---------------------------------------------------
             1          1          1  COUNT STOPKEY (cr=499532 pr=0 pw=0 time=24289612 us)
             1          1          1   HASH JOIN RIGHT SEMI (cr=499532 pr=0 pw=0 time=24289586 us cost=32 size=144 card=1)
             1          1          1    VIEW  VW_NSO_1 (cr=103 pr=0 pw=0 time=31110 us cost=29 size=98016 card=8168)
             1          1          1     COLLECTION ITERATOR PICKLER FETCH SDO_PQRY (cr=103 pr=0 pw=0 time=31104 us cost=29 size=16336 card=8168)
      16914892   16914892   16914892    PARTITION RANGE ALL PARTITION: 1 7 (cr=499429 pr=0 pw=0 time=28678375 us cost=3 size=6600 card=100)
      16914892   16914892   16914892     TABLE ACCESS FULL BIG_PARTITIONED_TABLE PARTITION: 1 7 (cr=499429 pr=0 pw=0 time=23406547 us cost=3 size=6600 card=100)
    
    

    I tried adding an indication / * + index (o BIG_PARTITIONED_TABLE_SPIND) * / but that did not help.

    I am struck this issue during testing of upgrade 10.2.0.5 to 12.1.0.2.  The query works perfectly on 10g - we note only that this question on 12 c.

    I can't use sdo_equal as the real mask that we want is equal + dommagescausdspar + covers.  I'm just using equal here to simplify the test.

    I use "rownum = 1" because I want to just the first result.  In practice I can rewrite probably is a FOR LOOP, I get out after the first result, but that seems all just awful.

    Any ideas?  If anyone has seen anything like this before?  Its an optimizer delivers really so I'm going to cross post the SQL Forum after a certain time, but thought I would post it here first.

    Thank you

    John

    Hi John,.

    Can you please try the following before your slow queries event?

    "ALTER session set events ' trace 54669 name context forever."

    Thank you

    Ying

  • Order by with Union

    select level as lvl --,1 as ordered 
    from dual
    connect by level <=5
    union all
    select rownum as lvl --,2 as ordered  
    from dual
    connect by level <=5 
    

    How to order the query after the UNION ALL clause in descending order

    My expected results

    1

    2

    3

    4

    5

    5

    4

    3

    2

    1

    Select * from (select level as lvl-, 1 as ordered

    of the double

    connect by level<>

    order by 1)

    Union of all the

    Select * from (select rownum as -lvl 2 as he ordered

    of the double

    connect by level<>

    order by 1 desc)

  • I can not activate a new order paid with a different email address

    After the trial period months using a gmail account, I paid a new order using an account of hotmail of mine, the order number of the answer of the adobe (for hotmail) can not be activated: my account is fixed with the old (and allegedly expired) gmail. Also when you try to change my ID in hotmail instead of gmail, it is said: "(impossible de changer,,,)." This is already a month and still the same.

    How can we get the money. Then I can make a new order using the gmail email account.

    Maybe European people who post here can help you with this question.

  • SQL performance problem associated with rownum.

    Dear Experts,

    I have a sql

    SELECT TEMP.col1, TEMP.col2, TEMP.col3, TEMP.col4, TEMP.col5, ROWNUM, not

    (SELECT col1, col2, col3, col4 FROM table1 ORDER BY DESC col4 col5) TEMP WHERE rownum between? and?

    When I put the value of range rownum 1 and 100, it works very well. But when I put 101 and 200 no records returned.

    So I modified it as fllows

    SELECT TEMP.col1, TEMP.col2, TEMP.col3, TEMP.col4, TEMP.col5,NWR No. OF

    (SELECT col1, col2, col3, col4, col5, rownum NWR FROM table1 ORDER BY DESC col4) TEMP WHERE NWR between? and?

    It works fine and giving results desire. But the issue here is the modified SQL becomes very slow. It gives results in 20 minutes. Although SQL earlier gave results in a few seconds.

    Records in table1 is 40 million.

    Is there another way to get good performance results accurate?

    Your help will be much appreciated.

    Kind regards

    DD

    Hi try this... If you want that data should be in the specific order (as order by desc col4, then you can use analytical ROW_NUMBER() function as below). Try it out below and let me know in case of any problems

    SELECT TEMP.col1,

    TEMP.col2,

    TEMP.col3,

    TEMP.col4,

    TEMP.col5,

    NWR NO.

    FROM (SELECT col1,

    col2,

    col3,

    COL4,

    col5,

    ROW_NUMBER() over (ORDER BY DESC of col4) rno

    FROM table1)

    NWR WHERE between 101 AND 200;

    (GOLD)

    SELECT TEMP.col1,

    TEMP.col2,

    TEMP.col3,

    TEMP.col4,

    TEMP.col5,

    NWR NO.

    FROM (SELECT col1,

    col2,

    col3,

    COL4,

    col5,

    ROW_NUMBER() OVER(ORDER BY col4 DESC) NWR

    FROM table1)

    WHERE NWR<=>

  • Need help with rownum query.

    Hello guys,.

    I'm working on this SQL charly, it's pretty simple and it worked very well, but then I tried to 'Join' a table to it and now I can't make it work.

    The following SQL code works here.

    Select *.

    Of

    (select a.*, rownum rnum

    Of

    (select a.field1, a.field2, a.field3, b.field4, b.field5, b.field6,

    b.Field7, b.field8, b.field9, b.field10, b.field11, b.field12,

    b.Field13, b.field14, b.field15, b.field16, b.field17,

    b.field19, b.field20, b.field21, b.field22, b.veh_field22

    from SCHEMA.tablename has,

    / * attach * / SCHEMA.tablename b

    order of a.tablename_ID) a

    where rownum < = 150

    )

    where rnum > = 147;

    But, when I try to JOIN the SCHEMA.tablename b it tells me that I should add a "right parenthesis.

    Will this work ROWNUM query even when you join other tables, or through it the fact off the coast in any way?

    Thank you

    Xev.

    Xev,

    I tried to reproduce your problem, but could not. Since you have not published the scripts required, I worked on your script schema SCOTT and its working fine.

    SELECT * FROM

    (

    SELECT a.*, rownum rnum

    Of

    (SELECT e.ename,

    d.DNAME

    FROM scott.emp e,.

    Scott.Dept d

    ORDER BY e.deptno) a

    WHERE rownum<>

    WHERE rnum > = 10;

    OUTPUT:

    ENAME DNAME RNUM

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

    CLARK RESEARCH 10

    MILLER ACCOUNTING 11

    KING OF ACCOUNTING 12

    SMITH, ACCOUNTANT 13

    JONES, ACCOUNTING 14

  • Pagination with rownum

    Hi all

    I have a PL/SQL query
    SELECT COLUMN1 from TABLE1 ORDER BY Column1 DESC
    Here the Column1 is a TIMESTAMP column (3).
    I lists the records retrieved by this query in my java Application.
    But I want to improve the performance of my application by selecting only 25 records at a time, which corresponds to the maximum number of records you can keep ina page of the application.
    If the user clicks on the button records only the 25 next Page must be extracted and displayed.
    I tried to use rownum
    SELECT COLUMN1 FROM
    (SELECT COLUMN1 from TABLE1 ORDER BY COLUMN1 DESC) A where ROWNUM clause BETWEEN 1 AND 25;

    It worked! . He recovered properly than the first 25 records.

    But trying to get the next 25 records using the sub query, I have nothing

    SELECT COLUMN1 FROM
    (SELECT COLUMN1 from TABLE1 ORDER BY COLUMN1 DESC) A where ROWNUM clause BETWEEN 26 AND 50;

    COLUMN1
    -------------------------

    0 selected lines

    Also the number of rows in the table is 99.

    SELECT Count (1) from TABLE1 ORDER BY COLUMN1 DESC
    COUNT (1)
    ----------------------
    99

    1 selected lines

    Could someone please help me?

    If there is no alternative possible pls share me.

    Christèle CS wrote:
    Hi all

    But trying to get the next 25 records using the sub query, I have nothing

    SELECT COLUMN1 FROM
    (SELECT COLUMN1 from TABLE1 ORDER BY COLUMN1 DESC) A where ROWNUM clause BETWEEN 26 AND 50;

    It wouldn't work that way to use ROWNUM.

    You can use analytical works as an alternative to ROWNUM.

    select *
      from (
               select column1, column2, ... columnN, row_number() over (order by column1 desc) rn
                 from table1
             ) a
    where a.rn between 1 and 25; --> You can provide 26 and 50 as well.
    
  • How to upgrade an ordered list with a constraint

    Hi friends,


    I need to update a column for all records in the table with a unique constraint

    ex - select rec_no in tablename;
    9
    8
    7
    6
    5

    now I have to update this as
    Select rec_no in tablename;
    8
    7
    6
    5
    4
    but when I do update tablename set rec_no = rec_no-1
    I get unique constraint error



    Please help me

    DJ wrote:
    but when I do update tablename set rec_no = rec_no-1
    I get unique constraint error

    No, you don't. Show us.

    Oracle ensures consistency of 'duress of education. " If you perform an update statement (which is what you say above), then the Oracle will not give you a constraint error.

    Because if she did, then we are all would have a serious problem: whether or not the update succeeds then depend on the order in which Oracle (ie. the implementation plan) happens to be updated lines. And we cannot have such behavior "undeterministic" (similar to what we would have if Oracle has not provided us with the error table mutation...).

    Just so try, or show us:

    create table uk_test
    (i number not null unique)
    /
    
    insert into uk_test values(4);
    insert into uk_test values(3);
    insert into uk_test values(2);
    
    commit;
    

    Now try these two:

    update (select * from uk_Test order by i desc) set i=i-1;
    
    update (select * from uk_Test order by i) set i=i-1;
    

    They both succeed. Oracle allows temporary constraint violations during at the execution of a statement inside. There is no need to define this constraint postponed here.

    I'm talking about consistency of statement here also-level constraint:

    http://rulegen.blogspot.nl/2012/01/statement-level-constraint-validation.html

  • order by with an additional condition?

    Hello

    Oracle 11g r2.

    I have a few items (let's say the dominoes of a domino game that are placed on one table in front of the other).
    Sometimes, between the 2 items, I have a beam (piece of wood) which is an element too.

    I have tables that store the entry and exit of each element and the distance accumulated between them.
    A point is identified by a name of area (where it is placed), a class, a number (not really, just an identifier) and type of point (entry (E) or output (S)).
    CREATE TABLE SPATIAL_POINTS (
         SPAT_ID INTEGER,
         SPAT_AREA_NAME VARCHAR2(10),
         SPAT_CLASS VARCHAR2(15),
         SPAT_NUMBER VARCHAR2(15),
         SPAT_PT VARCHAR2(1),
         ...
         CONSTRAINT PK_SPAT_ID PRIMARY KEY(SPAT_ID),
         CONSTRAINT FK_SPAT_AREA FOREIGN KEY(SPAT_AREA_NAME) REFERENCES AREAS(AREA_NAME),
         CONSTRAINT CHK_SPAT_PT CHECK(SPAT_PT) IN ('E','S')
    );
    
    CREATE TABLE ALL_COORDINATES (
         ALL_ID INTEGER,
         ALL_SPAT_ID INTEGER,
         ALL_CUMUL NUMBER(15,9),
         ...,
         CONSTRAINT PK_ALL_ID PRIMARY KEY(ALL_ID),
         CONSTRAINT FK_ALL_SPAT_ID FOREIGN KEY(ALL_SPAT_ID) REFERENCES SPATIAL_POINTS(SPAT_ID),
    );
    Here is an example of data:
    select
         spat_area_name as "AREA",
         spat_class as "CLASS",
         spat_number as "NUMBER",
         spat_pt as "POINT",
         all_cumul as "CUMUL DIST"
    from
         spatial_points inner join all_coordinates on spat_id = all_spat_id
    where
         spat_area_name = 'P61'
    order by
         all_cumul,
         spat_class,
         spat_number,
         spat_pt
    
    
    AREA     CLASS     NUMBER     POINT     CUMUL DIST
    
    P61     POUTRE     01     E     -0.07700
    P61     CLSNA     0105     E     0.00000
    P61     CLSNA     0105     S     0.00400
    P61     CLSNB     0110     E     0.05600
    P61     CLSNB     0110     S     0.12400
    P61     CLBPE     0125     E     0.37240
    P61     CLBPE     0125     S     0.37240
    P61     CLSNC     0130     E     0.44500
    P61     CLSNC     0130     S     0.45500
    P61     CLSNC     0140     E     0.79500
    P61     CLSNC     0140     S     0.80500
    P61     CLSNC     0160     E     0.99500
    P61     CLSNC     0160     S     1.00500
    P61     CLMTV     0165     E     1.06100
    P61     CLMTV     0165     S     1.14100
    P61     CLBPE     0166     E     1.18440
    P61     CLBPE     0166     S     1.18440
    P61     CLSNC     0170     E     1.19500
    P61     CLSNC     0170     S     1.20500
    P61     POUTRE     01     S     1.32300
    P61     POUTRE     02     E     1.36000
    P61     CLSND     0210     E     1.37750
    P61     CLSND     0210     S     1.42250
    P61     CLPBU     0215     E     1.50700
    P61     POUTRE     02     S     1.54200
    ...     ...     ...     ...     ...
    I want to display the points sorted by distance (as in the example), but I want to show at each point of exit right after the entry point, I don't want all the other points to apear beetween an entry and an exit point of the same element.
    I want to order by cumulative distance of entry points (E) and then add the exit point (S) after each entry point regardless of the cumulative distance of the outlet. I hope I'm understandable!

    Here is an example of what I want, according to the example above:
    AREA     CLASS     NUMBER     POINT     CUMUL DIST
    
    P61     POUTRE     01     E     -0.07700
    P61     POUTRE     01     S     1.32300
    P61     CLSNA     0105     E     0.00000
    P61     CLSNA     0105     S     0.00400
    P61     CLSNB     0110     E     0.05600
    P61     CLSNB     0110     S     0.12400
    P61     CLBPE     0125     E     0.37240
    P61     CLBPE     0125     S     0.37240
    P61     CLSNC     0130     E     0.44500
    P61     CLSNC     0130     S     0.45500
    P61     CLSNC     0140     E     0.79500
    P61     CLSNC     0140     S     0.80500
    P61     CLSNC     0160     E     0.99500
    P61     CLSNC     0160     S     1.00500
    P61     CLMTV     0165     E     1.06100
    P61     CLMTV     0165     S     1.14100
    P61     CLBPE     0166     E     1.18440
    P61     CLBPE     0166     S     1.18440
    P61     CLSNC     0170     E     1.19500
    P61     CLSNC     0170     S     1.20500
    P61     POUTRE     02     E     1.36000
    P61     POUTRE     02     S     1.54200
    P61     CLSND     0210     E     1.37750
    P61     CLSND     0210     S     1.42250
    P61     CLPBU     0215     E     1.50700
    ...     ...     ...     ...     ...
    In this way 'E' and ' go for the points of the "BEAM", and we don't care about cumulative distance of ' point.

    I tried some things with PARTITION BY, but without success.

    Any idea on how I can achieve this? I need a query, no PL/SQL.

    Thank you!

    Yann.

    As...

    select *
    from(
    select
        spat_area_name as "AREA",
        spat_class as "CLASS",
        spat_number as "NUMBER",
        spat_pt as "POINT",
        all_cumul as "CUMUL_DIST",
        min(CUMUL DIST) over(partition by spat_area_name) mn
    from
        spatial_points inner join all_coordinates on spat_id = all_spat_id
    where
         spat_area_name = 'P61'
    order by
         all_cumul,
         spat_class,
         spat_number,
         spat_pt)
    order by mn,AREA,CUMUL_DIST
    

    tested with the EMP table. The query below will be stopped first by empno, then it will show all employees of the particular department...

    SQL> select empno,deptno
      2      from scott.emp
      3      order by empno;
    
         EMPNO     DEPTNO
    ---------- ----------
          7369         20
          7499         30
          7521         30
          7566         20
          7654         30
          7698         30
          7782         10
          7788         20
          7839         10
          7844         30
          7876         20
          7900         30
          7902         20
          7934         10
    
    14 rows selected.
    
    SQL> select *
      2  from(
      3      select empno,deptno,min(empno) over(partition by deptno) mn
      4      from scott.emp
      5      order by empno
      6      )
      7  order by mn,deptno,empno;
    
         EMPNO     DEPTNO         MN
    ---------- ---------- ----------
          7369         20       7369
          7566         20       7369
          7788         20       7369
          7876         20       7369
          7902         20       7369
          7499         30       7499
          7521         30       7499
          7654         30       7499
          7698         30       7499
          7844         30       7499
          7900         30       7499
          7782         10       7782
          7839         10       7782
          7934         10       7782
    
    14 rows selected.
    

    Published by: JAC on April 3, 2012 19:40

Maybe you are looking for

  • HP Pavilion Notebook PC Internet questions G6

    Hi im having problems with internet on my laptop HP Pavilion G6, internet keeps dropping out and showing the yellow warning triangle. Internet still works fine on my I-Phone and a game console, so I think it's the laptop not the hub. After awhile the

  • Battery indicator does not

    I just installed the update and now my battery indicator does not work. This shows only one question mark.

  • Analysis of file

    Hello I am trying to write a code that reads data from a spreadsheet file, which has several lines. The recorded data have formatting that looks something like: Test series | Data1 | Data2. Data3. ..... SN1 | ##     | ##     | ##     |....... SN2 | #

  • cannot pair mobile mouse wireless Microsoft 6000 with a Toshiba bluetooth usb adapter

    I have a toshiba bluetooth usb adapter, which is supposed to be able to connect with up to 7 bluetooth devices, but I can't seem to do recognize/find my Microsoft 6000 wireless mobile mouse.  is it because the mouse has its own transceiver or I do so

  • Software BlackBerry made Blackberry connection problems with Outlook 2003?

    I tried to look through the forums to see if theres any other mention of this but could not find something but it definitely seems to be a problem with one of our PC My wife has a Win XP SP3 system and running Office 2003 and 2003 Ourlook which, unti