Question ROWNUM

HI team,

I get lines of a table TAB1 containing 1.6 million given. When I use the following query I can easily get the details...

Select * from abc. Tab1 where rx_tx_id = 376741709 and rownum between 1-199999

order of time_stamp;

BUT when we use other values other than 1, it will not look for all of the lines and NO error also... Please help me to fix this problem.

Select * from abc. Tab1 where rx_tx_id = 376741709 and rownum between 2 and 199999

order of time_stamp;

Hello

I suggest to look at the documentation of ROWNUM:

http://docs.Oracle.com/CD/B19306_01/server.102/b14200/pseudocolumns009.htm

From this link: "test Conditions for ROWNUM value to a positive integer is always wrong."

Your query can be written in the following form:

Select * from abc. Tab1 where rx_tx_id = 376741709 and (rownum > = 2 and rownum)<=>

order of time_stamp;

New from the documentation link... the first line is extracted and assigned ROWNUM = 1. This does not meet the condition if it is ignored. The next line is extracted and assigned ROWNUM = 1. This does not meet the condition if it is ignored. This continues until you have no lines left in the process.

You can try to use an analytical function to help out here. Something like:

Select * from (select TAB1.*, dense_rank() (time_stamp order) as Dr. of ABC. Tab1 where rx_tx_id = 37674170) where Dr. between 2 and 199999.

Others may have better ideas, but maybe that's something in the meantime, you can explore.

Tags: Database

Similar Questions

  • Question of rowNum

    Dear friends

    Given an array of simple employees with the names of employees and wages.

    for this query:

    Select rownum, salary
    from (select name, salary
    employees
    salary desc order)

    .. I am able to see the number of lines like 1,2,3,4,5...
    and the names of the employees and wages in descending order,

    However if I try to use:
    Select rownum, salary
    from (select name, salary
    employees
    salary desc order)
    where rownum = 2

    Why didn't he give me the second highest salary?

    In the case of:
    Select rownum, salary
    from (select name, salary
    employees
    salary desc order)
    where rownum = 1
    .. I am able to see the highest salary.


    Thanks for your help...

    Best

    Rownum is assigned to the lines of recoveries, so it always starts with 1. So query with ROWNUM = N where N > 1 will return all the lines. Use:

    select  first_name,
            salary
      from  (
             select  first_name,
                     salary,
                     rownum rn
               from  (
                      select  first_name,
                              salary
                        from  employees
                        order by salary desc
                     )
            )
      where rn = 2
    /
    

    Or better:

    select  first_name,
            salary
      from  (
             select  first_name,
                     salary,
                     row_number() over(order by salary desc) rn
               from  employees
            )
      where rn = 2
    /
    

    And don't forget, your query (identical to the ones I posted above) does not return second highest salary. Then, they return more employee paid.

    SY.

  • question regarding rownum

    Hello

    why we cannot use > rownum operator?

    Why should always use < =?

    is there a particular reason for this... why the following query will not work?
    select b.* from brnd b where rownum in (select rownum from brnd b where rownum <=3);

    Hello

    ROWNUM is assigned temporarily and re-used if the line is not ultimately selected for a reason any. The first line to enter the result (not necessarily the first line extracted) aura ROWNUM = 1 set.

    If this isn't what you want, then use the ROW_NUMBER analytic function instead of ROWNUM, or use ROWNUM in a subquery, save (as an alias for column), and then filter on this vlue in a great request.

  • question about sorting and rownum and subqueries.

    Can you explain why 4 below the test as it results results - with no return line?

    Identifier "PKG_INTRA_CUSTOMER_SEARCH.NAME" is a package function, which returns the value of a variable declared in the package body, the function returns the value ' e % '.
    Please note that 1 to 3 tests given all returned, but didn't test 4. Why? My porpouse is this test 4 would also return data.


    1. motion without 'rownum' and with 'Order of' returns 2 records:
    select q.*--, rownum
                ,PKG_INTRA_CUSTOMER_SEARCH.NAME
             from 
                ( 
                select c.ID, 
                   c.NAME, 
                   c.CODE      
                from V_CUSTOMER c   
                where 1=1 and  lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME  
                order by c.NAME, c.ID
                ) q
    
    
    10020     Ees Nimi     37810010237     e%
    10040     ewewrwe werwerwer          e%
    2 query with "rownum" and without "In order to" returns 2 records:
    select q.*, rownum
                ,PKG_INTRA_CUSTOMER_SEARCH.NAME
             from 
                ( 
                select c.ID, 
                   c.NAME, 
                   c.CODE      
                from V_CUSTOMER c   
                where 1=1 and  lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME  
                --order by c.NAME, c.ID
                ) q
    10020     Ees Nimi     37810010237     e%
    10040     ewewrwe werwerwer          e%
    3 application without 'rownum' and with 'Order of' returns 2 records:
    select q.*--, rownum
                ,PKG_INTRA_CUSTOMER_SEARCH.NAME
             from 
                ( 
                select c.ID, 
                   c.NAME, 
                   c.CODE      
                from V_CUSTOMER c   
                where 1=1 and  lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME  
                order by c.NAME, c.ID
                ) q
    10020     Ees Nimi     37810010237     e%
    10040     ewewrwe werwerwer          e%
    4 query with "rownum" and "In order to" returns 0 records:
              
    select q.*, rownum
                ,PKG_INTRA_CUSTOMER_SEARCH.NAME
             from 
                ( 
                select c.ID, 
                   c.NAME, 
                   c.CODE      
                from V_CUSTOMER c   
                where 1=1 and  lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME  
                order by c.NAME, c.ID
                ) q

    Hello
    You are right.

    Kind regards
    Bobin

  • Questions about the ASH

    I use 11g. I have the below SQLs for:

    1. get the top 10 CPU consuming sessions

    2. get the top 10 sessions consume I/O

    3. get the top 10 sessions pending

    4. to get the corresponding session and SQL mapping.

    My questions are:

    1 - is the filter "AND session_type is 'ORIGINAL'". "correct? I want to eliminate the system process.

    2. it may happen that some session_id returned from these SQLs have been disconnected. In this case how can I get the details of this session they will disappear from session$ v? Similarly, how can I get the SQLs returned from V$ sql?

    3. when I put the sight of ASH in a procedure, I get compilation error "PL/SQL: ORA-00942: table or view does not exist. I SELECT for ASH table access. I can select in session.

    SELECT *
    FROM 
    (
    SELECT session_id,  
           session_serial#,
           program,
           COUNT(*) AS cpu
    FROM v$active_session_history
    WHERE session_state= 'ON CPU'
    AND sample_time > sysdate - interval '30' minute
    AND session_type='FOREGROUND'  
    GROUP BY session_id,  
           session_serial#,
           program
    ORDER BY COUNT(*) DESC
    )
    WHERE ROWNUM <= 10
    ;
    SELECT *
    FROM 
    (
    SELECT session_id,  
           session_serial#,
           program,
           COUNT(*) AS IO
    FROM v$active_session_history
    WHERE session_state= 'WAITING'
    AND wait_class = 'User I/O'
    AND sample_time > sysdate - interval '30' minute
    AND session_type='FOREGROUND'  
    GROUP BY session_id,  
           session_serial#,
           program
    ORDER BY COUNT(*) DESC
    )
    WHERE ROWNUM <= 10
    ;
    
    SELECT *
    FROM 
    (
    SELECT session_id,  
           session_serial#,
           program,
           wait_class,
           COUNT(*) AS IO
    FROM v$active_session_history ash
    WHERE session_state= 'WAITING'
    --AND wait_class <> 'User I/O'
    AND sample_time > sysdate - interval '30' minute
    AND session_type='FOREGROUND'  
    GROUP BY session_id,  
           session_serial#,
           program,
           wait_class
    ORDER BY COUNT(*) DESC
    )
    WHERE ROWNUM <= 10
    ;
    SELECT DISTINCT session_id,
      session_serial#,
      sql_id
    FROM v$active_session_history
    
    
    
    

    I'm not sure that you are up to.

    1 - is the filter "AND session_type is 'ORIGINAL'". "correct? I want to eliminate the system process

    Yes. See http://docs.oracle.com/database/121/REFRN/GUID-69CEA3A1-6C5E-43D6-982C-F353CD4B984C.htm#REFRN30299

    2. it may happen that some session_id returned from these SQLs have been disconnected. In this case how can I get the details of this session they will disappear from session$ v? Similarly, how can I get the SQLs returned from V$ sql?

    You will never get "all sqls" even for active sessions. You must traceing on these sessions. Everything you see is currently active SQL.

    3. "PL/SQL: ORA-00942: table or view does not exist.

    If you put it in your code. You need more to select through a role.

    Try: grant select on sys.v_$ active_session_history to dba_user with the option grant.

    And an easier version of your code (an only SELECT and no ROWNUM ""))

    (User name instead of SID... but adjust it to your needs.)

    SELECT user_id, username, session_state, rn, cnt

    FROM (SELECT user_id, username, session_state, cnt

    ROW_NUMBER() on rn (partition session_state cnt DESC order)

    DE)

    SELECT COUNT (*) NTC, h.session_type, h.user_id, session_state, u.username

    V $ active_session_history h

    INNER JOIN dba_users u

    ON u.user_id = h.USER_ID

    WHERE h.sample_time > sysdate - interval '30' minute

    AND session_type = "FOREGROUND"

    AND session_state IN ("'ON CPU', ' user i/o","WAITING")

    GROUP BY

    h.user_id, u.username, h.session_type, h.session_state

    )

    )

    WHERE the rn<=>

    It will be useful.

    But you want to use it?

    Andy

  • Bug with an outer join, or &amp; Analytics function (or rownum)

    Hello

    Seems to be a combination of an outer join, OR and rownum confuses the CBO.

    First request is without rownum, the second is with rownum.

    The second query expects 203 t lines and never ends. It should behave the same as query 1, with 24 M lines.

    Remove the GOLD clause query 2 allows him to behave as a query 1, with 24 M lines.

    We never saw it? Is there a solution?

    SELECT *
      FROM message i
      LEFT JOIN (SELECT hi.message_id, hi.update_dt
                   FROM message_hist hi) h ON (t.id = h.master_id
                                           AND(t.update_dt = h.update_dt OR h.update_dt <TO_DATE('150901','RRMMDD')));
          
    -----------------------------------------------------------------------------------------------                                                                                                                                                                                                              
    | Id  | Operation           | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                                              
    -----------------------------------------------------------------------------------------------                                                                                                                                                                                                              
    |   0 | SELECT STATEMENT    |                         |    24M|    13G|   475G  (2)|999:59:59 |                                                                                                                                                                                                              
    |   1 |  NESTED LOOPS OUTER |                         |    24M|    13G|   475G  (2)|999:59:59 |                                                                                                                                                                                                              
    |   2 |   TABLE ACCESS FULL | MESSAGE                 |  8037K|  1318M| 29883   (2)| 00:06:59 |                                                                                                                                                                                                              
    |   3 |   VIEW              |                         |     3 |  1302 | 59136   (2)| 00:13:48 |                                                                                                                                                                                                              
    |*  4 |    TABLE ACCESS FULL| MESSAGE_HIST            |     3 |   168 | 59136   (2)| 00:13:48 |                                                                                                                                                                                                              
    -----------------------------------------------------------------------------------------------                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                 
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                          
    ---------------------------------------------------                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                 
       4 - filter("I"."MESSAGE_ID"="HI"."MESSAGE_ID" AND                                                                                                                                                                                                                                                         
                  ("HI"."UPDATE_DT"<TO_DATE('150901','RRMMDD') OR "I"."UPDATE_DT"="HI"."UPDATE_DT"))     
    ----------------              
    SELECT *
      FROM message i
      LEFT JOIN (SELECT hi.message_id, hi.update_dt
                      , ROWNUM
                   FROM message_hist hi) h ON (t.id = h.master_id
                                           AND(t.update_dt = h.update_dt OR h.update_dt <TO_DATE('150901','RRMMDD')));
         
    -------------------------------------------------------------------------------------------------                                                                                                                                                                                                            
    | Id  | Operation             | Name                    | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                                                                                                                                            
    -------------------------------------------------------------------------------------------------                                                                                                                                                                                                            
    |   0 | SELECT STATEMENT      |                         |   203T|   112P|   475G  (2)|999:59:59 |                                                                                                                                                                                                            
    |   1 |  NESTED LOOPS OUTER   |                         |   203T|   112P|   475G  (2)|999:59:59 |                                                                                                                                                                                                            
    |   2 |   TABLE ACCESS FULL   | MESSAGE                 |  8037K|  1318M| 29883   (2)| 00:06:59 |                                                                                                                                                                                                            
    |   3 |   VIEW                |                         |    25M|    10G| 59151   (2)| 00:13:49 |                                                                                                                                                                                                            
    |*  4 |    VIEW               |                         |    25M|    10G| 59151   (2)| 00:13:49 |                                                                                                                                                                                                            
    |   5 |     COUNT             |                         |       |       |            |          |                                                                                                                                                                                                            
    |   6 |      TABLE ACCESS FULL| MESSAGE_HIST            |    25M|  1355M| 59151   (2)| 00:13:49 |                                                                                                                                                                                                            
    -------------------------------------------------------------------------------------------------                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                 
    Predicate Information (identified by operation id):                                                                                                                                                                                                                                                          
    ---------------------------------------------------                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                 
       4 - filter("I"."MESSAGE_ID"="H"."MESSAGE_ID" AND ("I"."UPDATE_DT"="H"."UPDATE_DT" OR                                                                                                                                                                                                                          
                  "H"."UPDATE_DT"<TO_DATE('150901','RRMMDD')))         
     
    

    RowNum in a subquery is supposed to ensure that the subquery is evaluated completely before filtering, otherwise, how could you go out rownum?

    Your question is compounded because of the join condition that forces a level of nested loops, which means that the table should be fully analysed once for each line of conduct rowsource. You can either transform the join in an equijoin and allow a hash to run, or you join could materialize the subquery once.

    Allow the hash join:

    SELECT count (*)

    Message FROM

    LEFT JOIN (SELECT hi.message_id, hi.update_dt

    ROWNUM

    OF message_hist salvation) PM ON (i.message_id = h.message_id

    AND i.update_dt = h.update_dt)

    LEFT JOIN (SELECT hi.message_id, hi.update_dt

    ROWNUM

    OF message_hist salvation) h2 ON (i.message_id = h2.message_id

    AND h2.update_dt<>

    AND h2.update_dt <> i.update_dt)

    /

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

    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |

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

    |   0 | SELECT STATEMENT |              |     1.    66.   211 (1) | 00:00:01 |

    |   1.  GLOBAL TRI |              |     1.    66.            |          |

    |*  2 |   EXTERNAL RIGHT HASH JOIN |              |   800 | 52800 |   211 (1) | 00:00:01 |

    |*  3 |    VIEW                 |              |     1.    22.    70 (0) | 00:00:01 |

    |   4.     COUNTY |              |       |       |            |          |

    |   5.      TABLE ACCESS FULL | MESSAGE_HIST |     1.    22.    70 (0) | 00:00:01 |

    |*  6 |    EXTERNAL RIGHT HASH JOIN |              |   800 | 35200.   141 (1) | 00:00:01 |

    |   7.     VIEW                |              |     1.    22.    70 (0) | 00:00:01 |

    |   8.      COUNTY |              |       |       |            |          |

    |   9.       TABLE ACCESS FULL | MESSAGE_HIST |     1.    22.    70 (0) | 00:00:01 |

    |  10.     TABLE ACCESS FULL | MESSAGE |   800 | 17600 |    70 (0) | 00:00:01 |

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

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

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

    2 - access("I".") MESSAGE_ID '= 'H2'.' MESSAGE_ID "(+))"

    filter ("H2". "UPDATE_DT" (+)<>'I'. " ("' UPDATE_DT")

    3 - filter("H2".") UPDATE_DT "(+)<>

    6 - access("I".") "UPDATE_DT" ="H" UPDATE_DT "(+) AND"

    "I"." ' MESSAGE_ID ' ="H" MESSAGE_ID "(+))"

    Materialize the subquery:

    WITH h AS (SELECT / * + MATERIALIZE * / hi.message_id, hi.update_dt)

    ROWNUM

    OF message_hist salvation)

    SELECT count (*)

    Message FROM

    LEFT JOIN: ON (i.message_id = h.message_id

    AND (i.update_dt = h.update_dt OR h.update_dt<>

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

    | ID | Operation | Name                        | Lines | Bytes | Cost (% CPU). Time |

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

    |   0 | SELECT STATEMENT |                             |     1.    22.  1740 (0) | 00:00:01 |

    |   1.  TRANSFORMATION OF THE TEMPORARY TABLE.                             |       |       |            |       |

    |   2.   LOAD SELECT ACE | SYS_TEMP_0FD9D6810_5B8F6E67 |       |       |            |       |

    |   3.    COUNT                   |                             |       |       |            |       |

    |   4.     TABLE ACCESS FULL | MESSAGE_HIST |     1.    22.    70 (0) | 00:00:01 |

    |   5.   GLOBAL TRI |                             |     1.    22.            |       |

    |   6.    NESTED EXTERNAL LOOPS |                             |   800 | 17600 |  1670 (0) | 00:00:01 |

    |   7.     TABLE ACCESS FULL | MESSAGE |   800 | 17600 |    70 (0) | 00:00:01 |

    |   8.     VIEW                   |                             |     1.       |     2 (0) | 00:00:01 |

    |*  9 |      VIEW                  |                             |     1.    22.     2 (0) | 00:00:01 |

    |  10.       TABLE ACCESS FULL | SYS_TEMP_0FD9D6810_5B8F6E67 |     1.    22.     2 (0) | 00:00:01 |

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

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

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

    9 - filter("I".") ' MESSAGE_ID ' ="H" MESSAGE_ID' AND ('I'. "" "UPDATE_DT"="H" UPDATE_DT' OR

    "H"." UPDATE_DT ".<>

    You may need to change the first condition to make sure that you select the correct subquery.

    -edit

    Not able to view a plan but you can invade the second join condition select and then the result of a subquery with a predicate according to your requirement. This should delay the or rating and leave only an equijoin (although rowsource return may be slightly larger than the opposite).

    -Second edition, it did not work exactly when I tried it.

    A hybrid of the previous two plans with a slight modification of how he was imitating the GOLD:

    WITH h AS (SELECT / * + MATERIALIZE * / hi.message_id, hi.update_dt)

    ROWNUM Clotilde

    OF message_hist salvation)

    SELECT i.MESSAGE_ID

    i.UPDATE_DT

    COALESCE(h.message_id,h2.message_id) message_id

    , COALESCE (h.update_dt, h2.update_dt) update_dt

    Clotilde COALESCE (h.rown, h2.rown)

    Message FROM

    LEFT JOIN: ON (i.message_id = h.message_id

    AND i.update_dt = h.update_dt)

    LEFT JOIN: h2 WE (DECODE(h.message_id,,i.message_id) = h2.message_id - only try this if previous join returned NULL

    AND h2.update_dt<>

    /

    --------------------------------------------------------------------------------------------------------
    | ID | Operation | Name                      | Lines | Bytes | Cost (% CPU). Time |
    --------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |                           |     1.    66.     8 (0) | 00:00:01 |
    |   1.  TRANSFORMATION OF THE TEMPORARY TABLE.                           |       |       |            |          |
    |   2.   LOAD SELECT ACE | SYS_TEMP_0FD9D6605_28F27F |       |       |            |          |
    |   3.    COUNT                   |                           |       |       |            |          |
    |   4.     TABLE ACCESS FULL | MESSAGE_HIST |   150.  3300 |     2 (0) | 00:00:01 |
    |   5.   GLOBAL TRI |                           |     1.    66.            |          |
    |*  6 |    EXTERNAL RIGHT HASH JOIN |                           | 10497.   676K |     6 (0). 00:00:01 |
    |*  7 |     VIEW                   |                           |   150.  3300 |     2 (0) | 00:00:01 |
    |   8.      TABLE ACCESS FULL | SYS_TEMP_0FD9D6605_28F27F |   150.  3300 |     2 (0) | 00:00:01 |
    |*  9 |     OUTER HASH JOIN |                           |   328. 14432 |     4 (0) | 00:00:01 |
    |  10.      TABLE ACCESS FULL | MESSAGE |   200 |  4400 |     2 (0) | 00:00:01 |
    |  11.      VIEW                  |                           |   150.  3300 |     2 (0) | 00:00:01 |
    |  12.       TABLE ACCESS FULL | SYS_TEMP_0FD9D6605_28F27F |   150.  3300 |     2 (0) | 00:00:01 |
    --------------------------------------------------------------------------------------------------------

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

    6 - access("H2".") MESSAGE_ID "(+) = DECODE (TO_CHAR ('H'". "))" MESSAGE_ID"), NULL, 'I '. (("' MESSAGE_ID '))
    7 - filter("H2".") UPDATE_DT "(+)<>
    9 - access("I".") "UPDATE_DT" ="H" UPDATE_DT "(+) AND 'I'." "" ' MESSAGE_ID '="H" MESSAGE_ID "(+))"

    (This plan is another system if costs are not comparable)

  • 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

  • Problem with a complete refresh materialized view when using rownum

    Hi all

    I had a problem with rownum when complete using Refresh

    I use rownum when you create the materialized view, and this is the generation properly. But the question was when I even refreshing, rownum was not get sorted in ascending order.

    anyone encountered this scenario

    rownum is determined as the line came out, also "order by rownum" does absolutely nothing.

    http://docs.Oracle.com/CD/B19306_01/server.102/b14200/pseudocolumns009.htm

  • How to order rownum?

    Hello!

    I have a simple code that selects the fields in a table:

    SELECT
      ROWNUM,
      question,
      APEX_ITEM.RADIOGROUP(ROWNUM, YES_SCORE, 2,  apex_lang.message('YES'), p_item_id => ROWNUM||'y') yes,
      APEX_ITEM.RADIOGROUP(ROWNUM, NO_SCORE, 2,  apex_lang.message('NO'),  p_item_id => ROWNUM||'n') no
    FROM question q
    WHERE question.id = :TYPE 
    ORDER BY ORDER_ID,ROWNUM;
    

    Now, I had insert an ORDER_ID field in the table to make the admin output lines in certain order and Add ORDER BY line code.

    Who messed up the column ROWNUM.

    Add column rownum differently to get the line numbers appear in the proper order (1, 2, 3,...)?

    IM using APEX 4.2.1.

    Hello

    You may

    SELECT rownum

    x.question

    APEX_ITEM. RADIOGROUP (rownum

    x.yes_score

    2

    apex_lang.message ('YES')

    p_item_id-online rownum | (' y') Yes

    APEX_ITEM. RADIOGROUP (rownum

    x.no_score

    2

    apex_lang.message ('NO')

    p_item_id-online rownum | ("no) no

    FROM (SELECT q.question

    q.yes_score

    q.no_score

    QUESTION q

    WHERE q.question.id =: TYPE

    ORDER BY q.order_id

    ) x

    ;

    (I assumed that yes_score and no_score are the 'question' column; suggestion: use the alias for the table names and precede all columns with the corresponding alias)

    Best regards

    Bruno Vroman

  • apex_item. RadioGroup p_idx question of value

    All,

    I have an interactive data report with radio buttons 3. user can select a value radiobutton for processing.

    .......................................
    .......................................
    apex_item.radiogroup( p_idx => rownum , p_value => bestelling_id , p_selected_value => huidige_afdeling_id , p_display => 'LAB' , p_attributes => 'class="afdRadio afdLab" ' , p_onchange => 'javascript:setLab(this.value);' )  AS LAB ,
     apex_item.radiogroup( p_idx => rownum , p_value => bestelling_id , p_selected_value => huidige_afdeling_id , p_display => 'QC' , p_attributes => 'class="afdRadio afdQc" ' , p_onchange => 'javascript:setQC(this.value);' )  AS QC ,
    apex_item.radiogroup( p_idx => rownum , p_value => bestelling_id , p_selected_value => huidige_afdeling_id , p_display => 'Afhaaldesk' , p_attributes => 'class="afdRadio afdDesk" ' , p_onchange => 'javascript:setAfhaalDesk(this.value);' ) AS AFHAALDESK 
    ..............................
    
    
    
    
    

    Problem is that the report can return a large number of lines. Clicking a radiobutton and trying to present, sometimes an apex workflow exception is thrown. I discovered that this has to do with the value of rownum because the value of p_idx can be in 1 and 30.

    So what I did, is to replace rownum with a value of 1, this seems to have solved the problem.

    The other problem now is that when a user clicks a radiobutton on several lines, that is a single value according to the choice, but when to submit all the lines are subject for which the user has selected a value of the radiobutton.

    Example:

    The user select value LAB for 5 rows, but only to see the LAB in the last row selected radiobutton (not thinking that this line will be submitted), but all of the 5 ranks are submitted.

    With rownum all selected values are shown, but there again the we have the problem with the value of p_idx.

    Some tips on how I can fix this?

    Thank you

    Diana

    Hi Diana,

    This seems to be a wrong information:

    Problem is that the report can return a large number of lines. Clicking a radiobutton and trying to present, sometimes an apex workflow exception is thrown. I discovered that this has to do with the value of rownum because the value of p_idx can be in 1 and 30.

    Each APEX_ITEM. function has its first parameter as p_idx that can take a value between 1 and 50. Items by a column in tables which in turn when the page is submitted are mapped to the APEX_APPLICATION. G_F01 in APEX_APPLICATION. G_F50 arrays of type APEX_APPLICATION_GLOBAL. VC_ARR2 in apex session state.

    For the limits of the component you should refer to the following documentation: (see tabular forms)

    https://docs.Oracle.com/CD/E37097_01/doc.42/e35125/limits002.htm#HTMDB28632

    dianap says:

    Thanks Scott.

    I took the example of Vincent. But the problem is in the population of the p_idx with rownum parameter. Rownum can sometimes be greater than 30, and when this is the case, nothing can be submitted.

    Kind regards

    Diana

    Here the question of the solution of Vincent about the radiogroup will lines might exceed the > limit 50 when the rows in the underlying table are > 50.

    The solution uses the paging with the whole line displayed on a page of the report must be<50 (by="" default="" it="" is="" 15="">

    As Oracle APEX page submit takes into account only the game currently displayed rows (regardless what underlying table contains) for the treatment of the displayed tabular form.<50 rows="" pagination="" with="" vincent's="" solution="" will="">

    NOTE: Tabular normal every column has an index and the lines have no limitations, but in a solution of Vincent as it use rownum to index, so a new table will be created for each line.

    I hope that helps!

    Kind regards

    Kiran

  • How to cancel the limit rownum &lt; 1234...

    Hello

    I connect via the ODBC connection pool to the Vertica (HP) database.

    Vertica SQL does not work with the operator "rownum <...» ».

    But OBIEE generate instructions SQL DB, according to ResultRowLimit definition.

    For example:

    Select D1.c1 as D1.c2 as D1.c3 as D1.c4 as c1 c2 c3 c4

    (separate select 0 as c1,

    D1. C1 C2

    D1. C2 as c3,

    D1. C3 as c4

    Of

    (select T380477. PERIOD_NAME C1,

    T380477. PERIOD_NUM C2,

    T380477. PERIOD_ID as c3

    of XXBI_DIM_GL_PERIODS T380477

    ) D1

    order of c4, c3) D1

    where rownum < = 1000000000

    So the question is: is it possible to cancel the rownum limit?

    Thank you

    Ark

    Have you tried to disable ROWNUM_SUPPORTED in the features of the physical layer data base? Implementation of database objects and the Pools of connections - 11 g Release 1 (11.1.1)

  • Question about blank w / existing line

    Hello, I have a newbie question.

    I have a PERSON with the typical NAME, LASTNAME columns table. I filled the table w / names and lastnames. Then, I added the USERID column to use as the primary key. How can I fill the username? for example, put "00001" when FIRSTNAME = 'John', LASTNAME = 'Doe '?

    Thank you!

    Update person set userid = "00001" where FIRSTNAME = 'John' and LASTNAME = 'Doe '.

    or do all the lines in one go (as an initial charge)

    Update person set userid = to_char (rownum, ' 09999');

  • Insert the ROWNUM in a column of data type of NUMBER table

    Hello

    I have a table that has a column named "rank" of the NUMBER data type. Basically, I want to make an analysis of top-n and insert the ROWNUM with other columns in the table.

    Definition of table1:

    CREATE TABLE

    (

    col1 VARCHAR2 (10),

    Col2 NUMBER,

    NUMBER of col3,

    rank NUMBER

    );

    INSERT INTO table1

    SELECT col1, col2, col3, rownum

    DE)

    SELECT col1, col2, col3

    FROM table2

    ORDER BY DESC of col3

    )

    WHERE rownum < = 5;

    I get an error ORA-01722: invalid number. I think the mistake is virtual ROWNUM is not data type of NUMBER, so I tried to cast as CAST (ROWNUM AS NUMBER), but it does not work, same error. Can can you please shed some light on how to convert a ROWNUM number or if the issue is something else.

    you're right, your example worked. It is an example of table I just created just to illustrate the problem, but my real table was always showing the same problem. Weird, isn't? However when I added the column names after that insert the question but statement I resolved. Adding code

    INSERT INTO TABLE1

    (col1, col2, col3, rank) - added

    SELECT col1, col2, col3, rownum

    DE)

    SELECT col1, col2, col3

    FROM table2

    ORDER BY DESC of col3

    )

    WHERE rownum<=>

    So that means ROWNUM returns number; and another confusion: why the inclusion of the column has solved my problem when it is not necessary for your example. in any case thank you.

  • return value of rowNum

    Dear all,

    I have a table that contains records (customer, DataOfPurchasments) where a customer might be buying in different days. If I'm ready to measure the period of inactivity for this client, I have to do?

    I thought sort ASC customers in a new table to sort the rownum for each, the query is as below:

    create table t (Select customer, dataofPurch from the sale) order of 1, 2
    So what I get is a data sorted on rownum as below:

    Rownum, customer, Dt
    1, 1234, February 1, 2013
    2, 1234, 5 February 2013
    3, 1234, February 6, 2013
    4, 5678, February 6, 2013
    5, 5678, 8 February 2013

    The question, what I need to do if I want the output to be like below:

    Customer, Date1, Date2, inactivity
    1234, 01-Feb-2013, 05-Feb-2013, 4
    1234, 05-Feb-2013, 06-Feb-2013, 1
    5678, 06-Feb-2013, 08-Feb-20132

    I thought as in a query

    Select customer, Date Dt 1, Date2 X.Dt, Dt - X.Dt
    T, (Select client, Dt from T where rownum < rownum + 1) X
    where t.Customer = X.customer
    Group of customer X.Dt Date2, Date 1 Dt, Dt - X.Dt

    but it was not useful. So, how can I solve my problem?

    Best regards;

    You would probably have better luck asking this type of question in the SQL/PLSQL forum: {forum: id = 75}, but based on what I've seen, you just use analytics - LEAD() in particular and you don't even need to create another table. Lead() will allow you to watch the next row of data and use it in your application. Here's a query that you can use, but you would need to modify it slightly:

    with test_data
      as (select 1234 customer, to_date('02012013','MMDDYYYY') order_date from dual union all
          select 1234 customer, to_date('02052013','MMDDYYYY') order_date from dual union all
          select 1234 customer, to_date('02062013','MMDDYYYY') order_date from dual union all
          select 5678 customer, to_date('02062013','MMDDYYYY') order_date from dual union all
          select 5678 customer, to_date('02082013','MMDDYYYY') order_date from dual)
     select customer,
            order_date,
            lead(order_date, 1, null) OVER (PARTITION BY customer ORDER BY order_date NULLS LAST) next_order_date,
            lead(order_date, 1, null) OVER (PARTITION BY customer ORDER BY order_date NULLS LAST) - order_date num_days
       from test_data
      order by customer, order_date;
    

    Your query will probably look something like:

    select customer,
           dataofPurch,
           lead(dataofPurch, 1, null) OVER (PARTITION BY customer ORDER BY dataofPurch NULLS LAST) next_dataofPurch,
           lead(dataofPurch, 1, null) OVER (PARTITION BY customer ORDER BY dataofPurch NULLS LAST) - dataofPurch num_days
      from sales
     order by customer, dataofPurch;
    

    Hope this helps, but if not post the question in the forum SQL/PLSQL.

  • More question of trace

    Hello
    Is my version of db: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    I was getting this error:
    SQL> set autotrace on
    SP2-0618: Cannot find the Session Identifier.  Check PLUSTRACE role is enabled
    SP2-0611: Error enabling STATISTICS report
    So I googled and followed this link step by step
    Question about AUTOTRACE, SP2-0618 and SP2-0611
    But then I ran into the following situation
    SQL> drop user def cascade;
    
    User dropped.
    
    Enter user-name: abc
    Enter password:
    
    SQL> @/opt/Oracle/111/sqlplus/admin/plustrce.sql
    SQL> drop role plustrace;
    
    Role dropped.
    
    SQL> create role plustrace;
    
    Role created.
    
    SQL>
    SQL> grant select on v_$sesstat to plustrace;
    grant select on v_$sesstat to plustrace
                    *
    ERROR at line 1:
    ORA-00942: table or view does not exist
    
    
    SQL> grant select on v_$statname to plustrace;
    grant select on v_$statname to plustrace
                    *
    ERROR at line 1:
    ORA-00942: table or view does not exist
    
    
    SQL> grant select on v_$mystat to plustrace;
    grant select on v_$mystat to plustrace
                    *
    ERROR at line 1:
    ORA-00942: table or view does not exist
    
    
    SQL> grant plustrace to dba with admin option;
    
    Grant succeeded.
    
    SQL>
    SQL> set echo off
    Because they say the table or view does not exist, I did the following:
    SQL> desc v$sesstat;
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     SID                                                NUMBER
     STATISTIC#                                         NUMBER
     VALUE                                              NUMBER
    
    SQL> grant select on v_$sesstat to plustrace;
    grant select on v_$sesstat to plustrace
                    *
    ERROR at line 1:
    ORA-00942: table or view does not exist
    
    SQL> select * from v$sesstat
      2  where rownum < 2;
    
           SID STATISTIC#      VALUE
    ---------- ---------- ----------
             1          0          0
    I think I have the tables, but at the same time it is said table does not exist. I don't understand.
    Please advice.

    Published by: 934451 on March 20, 2013 07:51

    Published by: 934451 on March 20, 2013 07:53

    I think you must be having 'sysdba' privileges to grant on v_$ sesstat.

    I just tested and yes it must be sys in order to give grant on v_$ sesstat.

    Published by: TSharma on March 20, 2013 11:04

Maybe you are looking for

  • How to remove malware

    My son downloaded MSPaint, but it seems that the download has been infected by malware. Downloaded several programs that have not been approved including the plugin Bucksbee loyalty. I thought that when I took it, I would be able to use Google as my

  • LM336av: 650779-001 ram max

    Hello I searched the Internet and called the customer service (which wouldn't let me speak to a representative because my laptop is no more supported), and I just want to know how much ram can support the motherboard 650779-001.  The laptop at the LM

  • Set up a printer on a network

    In my network, there are about 75 computers and 7 printers. 5 printers are shared so you can search when adding a printer and they appear. The other 2 are color printers only we have and that you are connected to the computer of managers. I have full

  • display the original installation drivers

    Hey I have recently downgraded from windows 7 to my original operating system, windows vista Home premium, but when I installed vista family premium he showed he had sp2 but it doesn't bother me. so when I went to download my graphic driver nvidia or

  • new restore point takes me to where the system restore must be fact-Windows8 - can anyone help?

    This afternoon I did an update of pc in turn, I lost all my programs. Creating a new restore, point I put in the description box the day before the start date of pc, but it will not take me. Only options it shows are all after the beginning of misery