Pagination with rownum!

i've the following query....... for getting first 10 records
SELECT A.leave_trans_id,A.leave_category_id,A.emp_id, B.leave_description,C.first_name,C.last_name, to_char(A.from_date,'DD-Mon-YYYY') from_date, to_char(A.to_date,'DD-Mon-YYYY') to_date, CASE WHEN approve_or_reject='t' THEN 'Approved' WHEN approve_or_reject='f' THEN 'Rejected' END as leave_status, to_char(A.applied_date,'DD-Mon-YYYY') applied_date, A.reason_for_leave FROM eo_emp_leave_trans A,eo_emp_leave_category B,eo_emp_details C WHERE A.leave_category_id = B.leave_category_id(+) and C.emp_id = A.emp_id AND A.emp_id = '2' and ROWNUM BETWEEN 0 AND 10
after this i need records from 10 - 20 .But it's not possible by replacing the last part ,ie,ROWNUM BETWEEN 10 AND 20.
how can i solve my problem ?
thanks...
ann

Right a subquery to get rownum first and then put filter condition in outer query like this :
SELECT A.leave_trans_id,A.leave_category_id,A.emp_id, B.leave_description,C.first_name,C.last_name, to_char(A.from_date,'DD-Mon-YYYY') from_date, to_char(A.to_date,'DD-Mon-YYYY') to_date, CASE WHEN approve_or_reject='t' THEN 'Approved' WHEN approve_or_reject='f' THEN 'Rejected' END as leave_status, to_char(A.applied_date,'DD-Mon-YYYY') applied_date, A.reason_for_leave
FROM
( SELECT ROWNUM row_number, A.leave_trans_id,A.leave_category_id,A.emp_id, B.leave_description,C.first_name,C.last_name, to_char(A.from_date,'DD-Mon-YYYY') from_date, to_char(A.to_date,'DD-Mon-YYYY') to_date, CASE WHEN approve_or_reject='t' THEN 'Approved' WHEN approve_or_reject='f' THEN 'Rejected' END as leave_status, to_char(A.applied_date,'DD-Mon-YYYY') applied_date, A.reason_for_leave FROM eo_emp_leave_trans A,eo_emp_leave_category B,eo_emp_details C WHERE A.leave_category_id = B.leave_category_id(+) and C.emp_id = A.emp_id AND A.emp_id = '2'
) A
WHERE row_number BETWEEN 10 AND 20
Regards
Arun

Similar Messages

  • Issue While executing the Query for Pagination using ROWNUM with like

    Issue While executing the Query for Pagination using ROWNUM with like.
    Database is Oracle11G.
    Oracle Database Table contains 8-9 lakh records
    1) SQL equal (=)
    SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
    WHERE A.REFERENCE = 'KMF22600920'
    Execution Time:- 0.00869245 seconds
    Returns 2 resultsets
    2) SQL like (one %)
    SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
    WHERE A.REFERENCE = 'KMF22600920%'
    Execution Time:- 0.01094301 seconds
    Returns 2 resultsets
    3) SQL like (two%)
    SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
    WHERE A.REFERENCE like '%KMF22600920%'
    Execution Time:- 6.43989658 seconds
    Returns 2 resultsets
    In Pagination, we are using Modified version of SQL Query 3) with ROWNUM as mentioned below :-
    4) SELECT * FROM (
    SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
    WHERE REFERENCE like '%KMF22600920%' AND ROWNUM <= 20 ) WHERE RNUM > 0
    Execution Time:- Infinite
    ResultSets:- No as execution time is infinite
    a) Instead of like if we use = in the above query it is returning the 2 resultsets (execution time 0.02699282 seconds)
    b) Instead of two % in the above query, if use one example REFERENCE like 'KMF22600920%' it is returning the 2 resultsets (execution time 0.03313019 seconds)
    Issue:- When using two % in like in the above query i.e. REFERENCE like '%KMF22600920%' AND ROWNUM <= 20 ) , it is going to infinite.
    Could you please let us know what is the issue with two % used in like and rownum
    5) Modified version of Option1 query (move out the RNUM condition AND RNUM <= 20)
    SELECT * FROM (
    SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
    WHERE REFERENCE like '%KMF22600920%' ) WHERE RNUM > 0 AND RNUM <= 20
    Execution Time:- 7.41368914 seconds
    Returns 2 resultsets
    Is the above query is best optimized query which should be used for the Pagination or still can improve on this ?

    This would be easier to diagnose if there was an explain plan posted for the 'good' and 'bad' queries. Generally speaking using '%' on both sides precludes the use of any indexes.

  • How to use filter operator with ROWNUM

    I would like to add filter operator in my mapping with ROWNUM to reduce the ETL loading time during testing to ensure mapping is working, but I don't know how, please help provide me some guideline. Thank you.

    what is your owb version?
    Starting with Oracle Warehouse Builder 10.2.0.3, you can use the pseudocolumns ROWID and ROWNUM in mappings. The ROWNUM pseudocolumn returns a number indicating the order in which a row was selected from a table. The ROWID pseudocolumn returns the rowid (binary address) of a row in a database table.
    You can use the ROWID and ROWNUM pseudocolumns in Table, View, and Materialized View operators in a mapping. These operators contain an additional column called COLUMN USAGE that is used to identify attributes used as ROWID or ROWNUM. For normal attributes, this column defaults to TABLE USAGE. To use an attribute for ROWID or ROWNUM values, set the COLUMN USAGE to ROWID or ROWNUM respectively.
    You can map a ROWID column to any attribute of data type ROWID, UROWID, or VARCHAR2. You can map ROWNUM column to an attribute of data type NUMBER or to any other data type that allows implicit conversion from NUMBER.
    Note that ROWID and ROWNUM pseudocolumns are not displayed in the Data Object Editor since they are not real columns.
    Edited by: Darthvader-647181 on Oct 29, 2008 9:18 AM

  • Pagination with an array

    Hello, i am trying to figure out how to create pagination with an array. I have done it before with a query but i can't seem to figure out how to do this with an array. Can someone please help me out with this?

    I meant to say, its an array result set. I'm testing it with an array of 9 elements, and it knows that it should be 2 pages with 5 records each, but its expecting 10 results and i can't get it to work with 9.

  • TIP: Pagination with No URL Access

    My tip for enabling pagination with No URL Access security option has been submitted on htmldb studio.
    Unfortunately none of the carriage returns seem to remain so it has been published as a single block of text making it very hard to read!!
    Raj can you have a look at this so that it is readable
    The tip for switching a page into printer friendly mode should hopefully be published soon.

    The tip for switching a page into printer friendly
    mode should hopefully be published soon.Doesn't HTML DB already come with a printer-friendly page template in every theme? Can you post your tip on the forum also?
    Thanks

  • Pagination with orcale and jsp

    hi, i m new to java can any one tell me how to do pagination with my this codes
    String sqlCount = null;
    String sql = null;
    sql = "select * from HOME_LEASE_ ";
    sqlCount = "select count(*)from HOME_LEASE_ ";
    Enumeration e = request.getParameterNames();
    int i = 0;
    while(e.hasMoreElements()){
    String name = (String)e.nextElement();
    String search = new String(request.getParameter(name)).toUpperCase();
    if(i != 0 && (!search.isEmpty())){
    sql = sql +" and " + name +" like'" + search + "%'" ;
    sqlCount = sqlCount + " and " name" like '" + search + "%'" ;
    }else if((!search.isEmpty()) && (i == 0) ){
    sql = sql + " where " + name +" like '" + search + "%'" ;
    sqlCount = sqlCount + " where " + name+" like '" + search + "%'" ;
    ++i;
    if((sql != null) && (sqlCount != null)){
    DataAccess dB = new DataAccess();
    Connection conn = dB.getConnection();
    Statement stmtCount = dB.createStmt(conn);
    ResultSet rsCount = dB.executeQuery(sqlCount,stmtCount);
    rsCount.next();
    Statement stmt = dB.createStmt(conn);
    ResultSet rs = dB.executeQuery(sql,stmt);
    <% if(rs == null)
    out.println("<h3>No data found</h3>");
    else
    //out.println(rs.next());
    while(rs.next()) {
    //out.println("inside the result set");
    out.println("<tr>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getInt("phase") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getInt("file_no") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getString("se") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getString("str") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getString("qrno") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getString("typ") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getInt("perno") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getString("name") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getInt("total_plot_area_ocp") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getInt("TOT_PREM_AREA") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getInt("total_construction") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getLong("chargbl_construction") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getLong("add_open_construction") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getLong("TOT_PREM_AREA") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getLong("plinth") + "</a></td>");
    out.println( "<td><a href=survey.jsp?phase="+ rs.getString("phase")+"&file_no="+rs.getString("FILE_NO")+">"+ rs.getLong("std_plot_area") + "</a></td>");
    out.println("</tr>");
    dB.close(rsCount);
    dB.close(stmtCount);
    dB.close(rs);
    dB.close(stmt);
    dB.close(conn);
    }else{
    out.println("<center style=\"background-color:red\">Please enter values in text fields<h1></h1></center>");
    %>

    After examining your code, I think:
    You are not using JSP/HTML properly (using java to write out HTML). You can spend a tremendous amount of time with trial and error approaches in learning a technology and still not get much real understanding for your effort. I suggest a better use of those hours would be spent in reading a book on Java first, then a book on JSP. For a book on JSP, go to amazon.com and search for 'Javaserver pages'. Find a book that isn't too old and that has good reviews. Here is one (although its a bit dated):
    http://www.amazon.com/JavaServer-Pages-Edition-Hans-Bergsten/dp/0596005636/ref=sr_1_1?s=books&ie=UTF8&qid=1338821741&sr=1-1
    As far your database code goes, I suggest you read on-line articles on JDBC on how to get/use/close a database connection in a try/catch/finally block. The article will probably also help you write better SQL too. I don't think your question on pagination should be tackled until you learn JSP.

  • Old Theme:  Pagination with Ordenation

    Hi
    I need return a cursor for Client (java)
    I already read meny posts about article, I got to make pagination using this articles
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:76812348057
    http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html
    Implementing  Resultset   with  Pagination in a Web Application
    But my Problem is thar the user can to choice 3 columns diferents for to order and Asc ou Desc
    The Problem is thar the query is very large.
    Example The user Choice column 1 ASC or Column2 DESC or COLUMN8 Desc
    In other topic, tell me put as:
       ORDER BY decode(P_order,0, decode(P_coluna,1,LAST_NAME,2,CODE_NAME,3,VALUE)) ASC,
    decode(P_order,1,decode(P_coluna,1,LAST_NAME,2,CODE_NAME,3,VALUE))  DESCBut did not work, work only when P_coluna =1 , for other number return me error
    Put Query in Dynamic Query is Impossible is very great
    Some have some idea?

    I'm not sure why you think the size of the query
    makes it more difficult to use dynamic SQL. From
    your description of the problem, the only dynamic
    piece is the ORDER BY clause. Everything other than
    the ORDER BY clause is static.
    Turning this into dynamic may take some effort, but
    is far from impossible.Thank
    Look length of my query ?
        OPEN P_CURSOR FOR
        WITH NOTIFICACAO AS(
          SELECT 
           t1.cd_consultora,
           t1.dc_nome_consultora,
           t2.nm_notificacao_cn,
           t2.dt_notificacao_cn dt_notificacao,
           t2.dt_atendimento_notificado,
           t1.cd_tipo_estrutura_comercial,
           t1.cd_estrutura_comercial
            FROM t_consultora t1, nc.t_nc_notificacao_cn t2
           WHERE t2.dt_notificacao_cn BETWEEN w_DTA_INI AND w_DTA_FIM
             AND t2.cd_consultora = t1.cd_consultora
             AND t1.cd_setor = w_cd_setor
             AND t1.cd_tipo_estrutura_comercial = p_tp_estrutura_comercial
             AND t1.cd_estrutura_comercial = p_cd_estrutura_comercial),
        T_NOTIFICADA AS ( select Count(t1.nm_notificacao_cn) over (partition by  t1.cd_consultora,t1.nm_notificacao_cn ) QTD_NOTAS,
                                 Count(t2.nm_item_notificacao_cn) over (partition by  t1.cd_consultora,t1.nm_notificacao_cn ) QTD_ITENS,
                                 T3.*
                                  from nc.t_nc_notificacao_cn t1,
                                       nc.t_nc_item_notificacao_cn  T2,
                                       NOTIFICACAO                  T3 
                                   where       t1.dt_notificacao_cn >= to_date('01/09/2006','dd/mm/yyyy')
                                    and   t3.nm_notificacao_cn = t1.nm_notificacao_cn
                                   and    t1.nm_notificacao_cn = t2.nm_notificacao_cn
                                   and    ((t2.cd_tipo_item_nc = 4 and t2.cd_subtipo_item_nc = 6)
                                           or t2.cd_tipo_item_nc = 2 or t2.cd_tipo_item_nc = 3)
                                           and t3.cd_consultora = t1.cd_consultora (+)  )  ,
        T_BLOQUEADA AS ( SELECT T4.* FROM
                     (SELECT  T3.*,
                            CASE WHEN T3.BLOQUEADA = -1 THEN  'Bloqueada'
                                 WHEN  T3.BLOQUEADA = 0 THEN
                              (CASE WHEN T3.QTD_NOTAS > 2 THEN
                                 CASE WHEN T3.QTD_ITENS > 8 THEN 'Atencao / Analise'
                                 ELSE
                                    'Normal'
                                 END
                               ELSE
                                 'Atencao / Analise'   
                              END)
                             END OBSERVACAO
                      FROM  (SELECT CASE WHEN NVL(T2.ID_CN_BLOQUEADA,1) = 1 then -1
                                   WHEN NVL(T2.ID_CN_BLOQUEADA,1) = 0  THEN 0
                                   END BLOQUEADA, T1.*
                        FROM   T_NOTIFICADA T1,
                               T_PS_CONSULTORA T2 
                               WHERE T1.CD_CONSULTORA = T2.CD_PESSOA)T3) T4 )
            select *
              from (SELECT t1.*, ROWNUM r_linha
               FROM (SELECT  cd_consultora,
                       dc_nome_consultora,
                       TELEFONE1,
                       TELEFONE2,
                       --fnc_busca_telefone(CD_CONSULTORA, 1) TELEFONE1,
                       -- fnc_busca_telefone(CD_CONSULTORA, 2) TELEFONE2,
                        EMAIL,
                        observacao,
                       nm_notificacao_cn,
                       nvl(vl_total_final,0) vl_total_final,                  
                       dt_notificacao,
                       qt_produto_item_nc,
                      sg_notificacao,
                      ID_SITUACAO,
                       qtd_registros
                    FROM (SELECT /*+ INDEX(W5 I0_NC_TIPO_ITEM_NC) */
                       W1.cd_consultora,
                       W1.dc_nome_consultora,
                       fnc_busca_telefone(w1.CD_CONSULTORA, 1) TELEFONE1,
                       fnc_busca_telefone(w1.CD_CONSULTORA, 2) TELEFONE2,
                       fnc_busca_email(w1.CD_CONSULTORA) EMAIL,
                       W1.OBSERVACAO observacao,
                       W1.nm_notificacao_cn,
                       sum(W4.qt_produto_nf *
                           W4.vl_unitario_final_produto_nf) OVER(PARTITION BY W1.cd_consultora, W1.nm_notificacao_cn) vl_total_final,
                       W1.dt_notificacao,
                       sum(W4.qt_produto_nf) OVER(PARTITION BY W1.cd_consultora, W1.nm_notificacao_cn) qt_produto_item_nc,
                       'PENDENTE' sg_notificacao,
                       W5.dc_tipo_item_nc ID_SITUACAO,
                       W_qtd_registros qtd_registros
                        FROM T_BLOQUEADA               W1,
                             nc.t_nc_item_notificacao_cn W2,
                             nc.t_nc_produto_item_nc     W3,
                             nc.t_nc_produto_item_nf     W4,
                             nc.t_nc_tipo_item_nc        W5
                       WHERE W1.dt_atendimento_notificado is null
                         and W1.nm_notificacao_cn =
                             W2.nm_notificacao_cn
                         and W2.cd_tipo_item_nc = W5.cd_tipo_item_nc
                         and W2.nm_notificacao_cn =
                             W3.nm_notificacao_cn(+)
                         and W2.nm_item_notificacao_cn =
                             W3.nm_item_notificacao_cn(+)
                         and W3.nm_notificacao_cn =
                             W4.nm_notificacao_cn(+)
                         and W3.nm_item_notificacao_cn =
                             W4.nm_item_notificacao_cn(+)
                         and W3.nm_sequencia_produto_item_nc =
                             W4.nm_sequencia_produto_item_nc(+)
                         and W2.cd_tipo_item_nc not in (6, 7)
                         and ((W2.id_situacao_item_nc = 1) OR
                             (W2.id_situacao_item_nc = 3 OR
                             W2.id_solucao_definida is not null))
                      UNION
                      SELECT /*+ INDEX(W5 I0_NC_TIPO_ITEM_NC) */
                       W1.cd_consultora,
                       W1.dc_nome_consultora,
                       fnc_busca_telefone(w1.CD_CONSULTORA, 1) TELEFONE1,
                       fnc_busca_telefone(w1.CD_CONSULTORA, 2) TELEFONE2,
                       fnc_busca_email(w1.CD_CONSULTORA) EMAIL,
                       W1.OBSERVACAO observacao,
                       W1.nm_notificacao_cn,
                       sum(W4.qt_produto_nf *
                           W4.vl_unitario_final_produto_nf) OVER(PARTITION BY W1.cd_consultora, W1.nm_notificacao_cn) vl_total_final,
                       W1.dt_notificacao,
                       sum(W4.qt_produto_nf) OVER(PARTITION BY W1.cd_consultora, W1.nm_notificacao_cn) qt_produto_item_nc,
                       'ATENDIDO' sg_notificacao,
                       W5.dc_tipo_item_nc ID_SITUACAO,
                       W_qtd_registros qtd_registros
                        FROM T_BLOQUEADA                W1,
                             nc.t_nc_item_notificacao_cn W2,
                             nc.t_nc_produto_item_nc     W3,
                             nc.t_nc_produto_item_nf     W4,
                             nc.t_nc_tipo_item_nc        W5
                       WHERE W1.dt_atendimento_notificado is not null
                         and W1.nm_notificacao_cn =
                             W2.nm_notificacao_cn
                         and W2.cd_tipo_item_nc = W5.cd_tipo_item_nc
                         and W2.nm_notificacao_cn =
                             W3.nm_notificacao_cn(+)
                         and W2.nm_item_notificacao_cn =
                             W3.nm_item_notificacao_cn(+)
                         and W3.nm_notificacao_cn =
                             W4.nm_notificacao_cn(+)
                         and W3.nm_item_notificacao_cn =
                             W4.nm_item_notificacao_cn(+)
                         and W3.nm_sequencia_produto_item_nc =
                             W4.nm_sequencia_produto_item_nc(+)
                             )T2
                    --   ORDER BY  DECODE(p_nm_asc_desc,0,DECODE(p_nm_col_ordem ,1, t2.cd_consultora,2,t2.dc_nome_consultora,t2.cd_consultora)) ASC
                      -- DECODE(p_nm_asc_desc,1,DECODE(p_nm_col_ordem ,1, cd_consultora,2,dc_nome_consultora)) desc
                             ) T1
               where rownum <= W_TO_REC)
             where r_linha >= W_FROM_REC;
      ORDER BY is with commentary because did not work, I tried with Dynamic Sql , but return me many errors

  • Optimal pagination with SELECT?

    Hi!
    Tom and others recommend this for pagination:
    select *
      from ( select a.*, rownum r
               from ( select *
                        from t
                       where x = :host_variable
                       order by y ) a
              where rownum < :HigerBound )
    where r > :LowerBoundSource: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:76812348057
    But now I am maintaining some code, where this form is used:
    select *
    from (select a.*, rownum r
               from ( select *
                        from t
                       where x = :host_variable
                       order by y ) a
            ) where r<=higherBound AND r>lowerBound;Is there a good reason to move the higherBound check into the second SELECT?
    Regards,
    David
    This is on Oracle 10.2

    xerces8 wrote:
    Is there a good reason to move the higherBound check into the second SELECT?No. the code you posted from Tom will remove rows sooner than the second set of code you posted. I'd stick with that construct.

  • How to do pagination with oracle along with java

    hi
    i want to know how to use pagination codes along with java.

    Are you sure that you're on the right forum? This is the forum for Berkeley DB, Java Edition, and we don't support SQL.
    Linda

  • Af:table range navigation and select  with rownum

    I'm trying to use af:table to display some data (long list), but the value attribute always returns the entire list. (Basic example)
    I'd like to use the range navigation so the application only select a sublist from the database (using rownum between x and y) and also display the navigation pane with all the pages, but I was only able to get the specific page with no navigation pane.
    Does anyone have a good example on how to use the range navigation with selects/rownum?

    Assuming I have an untitled1.jspx page with an Untitled1.java backing bean and an <af:table> on my page whose whose binding attribute is set to the EL expression #{Untitled1.table} to expose the table UI component in the backing bean, and a rangeChangeListener set to the EL expression #{Untitled1.onRangeChanged}, then with the following backing bean class, I seem to have been able to disable the user's picking the "Show all" option. It still appears in the list, but visually picking it stays on the current range of rows.
    package test.backing;
    import oracle.adf.view.faces.component.core.data.CoreTable;
    import oracle.adf.view.faces.event.RangeChangeEvent;
    public class Untitled1 {
      private CoreTable table;
      public Untitled1() {
      public void onRangeChanged(RangeChangeEvent rangeChangeEvent) {
        int newStart = rangeChangeEvent.getNewStart();
        int newEnd = rangeChangeEvent.getNewEnd();
        if (newEnd - newStart > getTable().getRows()) {
          int oldEnd = rangeChangeEvent.getOldEnd();
          int oldStart = rangeChangeEvent.getOldStart();
          queueRangeChangeEventForTable(newStart, newEnd, oldStart, oldEnd);
      private void queueRangeChangeEventForTable(int oldStart, int oldEnd,
                                                 int newStart, int newEnd) {
        RangeChangeEvent rce =
          new RangeChangeEvent(getTable(), oldStart, oldEnd, newStart, newEnd);
        getTable().queueEvent(rce);
      public void setTable(CoreTable table) {
        this.table = table;
      public CoreTable getTable() {
        return table;
    }

  • Prob. with where clause with rownum

    hi
    i have a table with the following columns
    SQL> desc mark
    Name Null? Type
    STUDENTCODE NUMBER(3)
    MARK1 NUMBER(2)
    MARK2 NUMBER(3)
    and here are the rows in it
    SQL> select * from mark ;
    STUDENTCODE MARK1 MARK2
    1 20 40
    2 70 80
    3 80 90
    4 90 99
    12 13 35
    5 90 80
    6 78 87
    i wanna sum mark1 and mark2 and list down the rows with the top 2 rows
    i tried to first list down all the rows in the order of sum with the following stat.
    SQL> select studentcode,mark1+mark2 from mark order by mark1+mark2 desc
    STUDENTCODE MARK1+MARK2
    4 189
    3 170
    5 170
    6 165
    2 150
    1 60
    12 48
    it worked fine. but i used a where clause to get the first 2 rows and here is what i got.
    SQL> select studentcode,mark1+mark2 from mark where rownum < 3 order by (mark1+mark2) desc
    STUDENTCODE MARK1+MARK2
    3 170
    2 150
    1 60
    as You can see, i don't get the req. result.
    how do i get the prob. solved ?

    For Oracle versions prior to 8.1.5, you will have to create a view and then incorporate that view into your select statement.
    create or replace view my_view
    is
    select studentcode, mark1 + mark2
    from mark
    order by mark1 + mark2 desc;
    select *
    from my_view
    where rownum <= 2

  • Query with rownum

    Here's a tricky one that has stumped me. I have two queries below :
    The first query should list me records ordered by apxl_log_id field desc(first 50).
    The second query should list me records ordered by apxl_log_id field desc(first 100). The only difference is in the number of records retrieved.
    In other words, all 50 records in the first query should be there in the second query results as well !! because i am ordering it in descending order of apxl_log_id field.
    However, The first query gives me starting with 2268 whereas the other one starts with 2283. My questions is, where are the records in the second query with apxl_log_id from 2268 to 2282 ? (there are 15 of them missing) ?
    What could be the reason ?
    SELECT apxl_log_id,apxl_srvr_nm FROM apxl_appl_xcptn_log WHERE ROWNUM <= nvl(50,(select count(*) from apxl_appl_xcptn_log))
    ORDER BY apxl_log_id desc
    Gives me, 2283
    2268     NOT SPECIFIED
    2267     NOT SPECIFIED
    2266     NOT SPECIFIED
    2265     NOT SPECIFIED
    2264     NOT SPECIFIED
    2263     NOT SPECIFIED
    2262     NOT SPECIFIED
    2261     NOT SPECIFIED
    2260     NOT SPECIFIED
    2259     NOT SPECIFIED
    2190     NOT SPECIFIED
    2113     NOT SPECIFIED
    2112     NOT SPECIFIED
    2111     NOT SPECIFIED
    2110     NOT SPECIFIED
    2109     NOT SPECIFIED
    2108     NOT SPECIFIED
    2107     NOT SPECIFIED
    2081     NOT SPECIFIED
    1925     NOT SPECIFIED
    1917     NOT SPECIFIED
    1916     NOT SPECIFIED
    1915     NOT SPECIFIED
    1914     NOT SPECIFIED
    1913     NOT SPECIFIED
    1912     NOT SPECIFIED
    1911     NOT SPECIFIED
    1910     NOT SPECIFIED
    1885     NOT SPECIFIED
    1876     NOT SPECIFIED
    1874     NOT SPECIFIED
    1872     NOT SPECIFIED
    1871     NOT SPECIFIED
    1870     NOT SPECIFIED
    1869     NOT SPECIFIED
    1865     NOT SPECIFIED
    1864     NOT SPECIFIED
    1863     NOT SPECIFIED
    1848     NOT SPECIFIED
    1847     NOT SPECIFIED
    1846     NOT SPECIFIED
    1839     NOT SPECIFIED
    1837     NOT SPECIFIED
    1831     NOT SPECIFIED
    1830     NOT SPECIFIED
    1829     NOT SPECIFIED
    1828     NOT SPECIFIED
    1827     NOT SPECIFIED
    1822     NOT SPECIFIED
    1819     NOT SPECIFIED
    SELECT apxl_log_id,apxl_srvr_nm FROM apxl_appl_xcptn_log WHERE ROWNUM <= nvl(100,(select count(*) from apxl_appl_xcptn_log))
    ORDER BY apxl_log_id desc
    2283     NOT SPECIFIED
    2282     NOT SPECIFIED
    2281     NOT SPECIFIED
    2278     NOT SPECIFIED
    2277     NOT SPECIFIED
    2276     NOT SPECIFIED
    2275     NOT SPECIFIED
    2274     NOT SPECIFIED
    2273     NOT SPECIFIED
    2272     NOT SPECIFIED
    2268     NOT SPECIFIED
    2267     NOT SPECIFIED
    2266     NOT SPECIFIED
    2265     NOT SPECIFIED
    2264     NOT SPECIFIED
    2263     NOT SPECIFIED
    2262     NOT SPECIFIED
    2261     NOT SPECIFIED
    2260     NOT SPECIFIED
    2259     NOT SPECIFIED
    2237     NOT SPECIFIED
    2236     NOT SPECIFIED
    2235     NOT SPECIFIED
    2234     NOT SPECIFIED
    2233     NOT SPECIFIED
    2232     NOT SPECIFIED
    2190     NOT SPECIFIED
    2138     NOT SPECIFIED
    2137     NOT SPECIFIED
    2133     NOT SPECIFIED
    2132     NOT SPECIFIED
    2131     NOT SPECIFIED
    2130     NOT SPECIFIED
    2129     NOT SPECIFIED
    2128     NOT SPECIFIED
    2127     NOT SPECIFIED
    2126     NOT SPECIFIED
    2125     NOT SPECIFIED
    2124     NOT SPECIFIED
    2123     NOT SPECIFIED
    2122     NOT SPECIFIED
    2121     NOT SPECIFIED
    2120     NOT SPECIFIED
    2119     NOT SPECIFIED
    2118     NOT SPECIFIED
    2117     NOT SPECIFIED
    2116     NOT SPECIFIED
    2113     NOT SPECIFIED
    2112     NOT SPECIFIED
    2111     NOT SPECIFIED
    2110     NOT SPECIFIED
    2109     NOT SPECIFIED
    2108     NOT SPECIFIED
    2107     NOT SPECIFIED
    2106     NOT SPECIFIED
    2105     NOT SPECIFIED
    2104     NOT SPECIFIED
    2103     NOT SPECIFIED
    2102     NOT SPECIFIED
    2081     NOT SPECIFIED
    2017     test
    1925     NOT SPECIFIED
    1923     NOT SPECIFIED
    1922     NOT SPECIFIED
    1921     NOT SPECIFIED
    1920     NOT SPECIFIED
    1919     NOT SPECIFIED
    1918     NOT SPECIFIED
    1917     NOT SPECIFIED
    1916     NOT SPECIFIED
    1915     NOT SPECIFIED
    1914     NOT SPECIFIED
    1913     NOT SPECIFIED
    1912     NOT SPECIFIED
    1911     NOT SPECIFIED
    1910     NOT SPECIFIED
    1886     test
    1885     NOT SPECIFIED
    1876     NOT SPECIFIED
    1874     NOT SPECIFIED
    1872     NOT SPECIFIED
    1871     NOT SPECIFIED
    1870     NOT SPECIFIED
    1869     NOT SPECIFIED
    1865     NOT SPECIFIED
    1864     NOT SPECIFIED
    1863     NOT SPECIFIED
    1848     NOT SPECIFIED
    1847     NOT SPECIFIED
    1846     NOT SPECIFIED
    1839     NOT SPECIFIED
    1837     NOT SPECIFIED
    1832     NOT SPECIFIED
    1831     NOT SPECIFIED
    1830     NOT SPECIFIED
    1829     NOT SPECIFIED
    1828     NOT SPECIFIED
    1827     NOT SPECIFIED
    1822     NOT SPECIFIED
    1819     NOT SPECIFIED

    Order by is applied after the where clause, so you query returns the first 50 or 100 random rows and then orders them.
    You need to use an in line view like this
    select * from
      SELECT apxl_log_id,apxl_srvr_nm
      FROM apxl_appl_xcptn_log
      ORDER BY apxl_log_id desc
    WHERE ROWNUM <= nvl(50,(select count(*) from apxl_appl_xcptn_log))

  • Sql Query Plan with ROWNUM

    Oracle 10g:
    I have a table with index, when I run that query on that index it's fine. I get into problem if I add ROWNUM in that query, query slows down from 1 sec to 30 sec. I don't know why. for eg:
    select * from (select * from A where b = 1) where ROWNUM < 1000 becomes very slow:
    Query Plan for select * from A where b = 1 (Query is just an example):
    Rows     Plan     
    208912     SELECT STATEMENT      
    208912     SORT ORDER BY      
    208912     HASH JOIN RIGHT OUTER      
    408     INDEX FULL SCAN PK_BAD_ACK_TASK     
    208912     HASH JOIN RIGHT OUTER      
    16     INDEX FULL SCAN PK_INFORMATIONAL_TASK     
    208912     HASH JOIN RIGHT OUTER      
    1     INDEX FULL SCAN PK_SYSTEM_ERROR_TASK     
    208912     HASH JOIN RIGHT OUTER      
    1     INDEX FULL SCAN PK_REJECTED_TRANSMISSION     
    208912     HASH JOIN RIGHT OUTER      
    1     INDEX FULL SCAN PK_ONHOLD_TASK     
    208912     HASH JOIN RIGHT OUTER      
    329465     INDEX FAST FULL SCAN PK_FAILED_MESSAGE     
    208912     TABLE ACCESS FULL TASK     
    Query when I add ROWNUM (slow query as mentioned above):
    Rows     Plan     
    999     SELECT STATEMENT      
    <NULL>     COUNT STOPKEY      
    208912     VIEW      
    208912     SORT ORDER BY STOPKEY      
    208912     HASH JOIN RIGHT OUTER      
    408     INDEX FULL SCAN PK_BAD_ACK_TASK     
    208912     NESTED LOOPS OUTER      
    208912     NESTED LOOPS OUTER      
    208912     NESTED LOOPS OUTER      
    208912     HASH JOIN RIGHT OUTER      
    329465     INDEX FAST FULL SCAN PK_FAILED_MESSAGE     
    208912     HASH JOIN RIGHT OUTER      
    16     INDEX FULL SCAN PK_INFORMATIONAL_TASK     
    208912     TABLE ACCESS FULL TASK     
    1     INDEX FAST FULL SCAN PK_ONHOLD_TASK     
    1     INDEX FAST FULL SCAN PK_REJECTED_TRANSMISSION     
    1     INDEX FAST FULL SCAN PK_SYSTEM_ERROR_TASK

    user628400 wrote:
    Oracle 10g:
    I have a table with index, when I run that query on that index it's fine. I get into problem if I add ROWNUM in that query, query slows down from 1 sec to 30 sec. I don't know why. for eg:Some notes:
    * When using ROWNUM the cost based optimizer switches to a FIRST_ROWS_N mode, this might explain the significant difference in the execution plan
    * Try to get a more meaningful output using DBMS_XPLAN.DISPLAY
    * Since you're already on 10g, try to compare the actual cardinalities to the estimates using DBMS_XPLAN.DISPLAY_CURSOR with the "ALLSTATS LAST" option and the GATHER_PLAN_STATISTICS hint.
    See e.g. here for more information how to do it: http://jonathanlewis.wordpress.com/2006/11/09/dbms_xplan-in-10g/
    This way you should be able to tell where the optimizer assumptions go wrong so that it thinks that the second one is better than the first one
    A simple remedy you might want to try that should get you back to plan 1 is the following:
    select * from (
    select ROWNUM as rn, a.* from (select * from A where b = 1 ORDER BY<your_order_criteria>) a
    where rn < 1000;Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/
    Edited by: Randolf Geist on Jan 11, 2009 9:33 PM
    Added the obvious sort ORDER BY

  • Pagination with url parameter?

    I have a page that displays the contents of a mysql database
    via a dynamic table.
    currently I have the recordset query set to filter the id by
    url parameter "catID".
    So page?catID=5 displays the contents of record id 5 of the
    mysql table.
    I am trying to add pagination to this page but do not know
    what I am doing :L
    I can use the wizard to place pagination if I remove the
    filter on the query, and happily page through all the
    records....however I want my cake and want to eat it to...so I
    really want to get the pagination working and still be able to use
    the url parameter function to pinpoint records.
    Thanks for your time and assistance.
    Saw

    Saw_duuhst wrote:
    > dreamweaver cs3, mysql, php
    Just make sure your recordset is filtering from the
    querystring and your
    pagination links should be inserting them too. In all the ASP
    pages I
    have made with pagination they always carry over the
    querystring.
    Dooza
    Posting Guidelines
    http://www.adobe.com/support/forums/guidelines.html
    How To Ask Smart Questions
    http://www.catb.org/esr/faqs/smart-questions.html

  • Pagination with conditional text

    Hello,
    We have an classroom book we want to put conditional instructor information into but I'm stumped on how to maintain pagination so that the instructor pages do not have page numbers and the instructor's versions will have the same page numbering (while physically having more pages, due to instructor material) as the student version with the conditional instructor text turned off.
    Thanks for any help, sorry if I'm missing the obvious.

    mt.mz. wrote:
    Hello,
    We have an classroom book we want to put conditional instructor information into but I'm stumped on how to maintain pagination so that the instructor pages do not have page numbers and the instructor's versions will have the same page numbering (while physically having more pages, due to instructor material) as the student version with the conditional instructor text turned off.
    Thanks for any help, sorry if I'm missing the obvious.
    In earlier versions, a FrameMaker bug permitted a trick page layout that employed two independent text flows - Flow: A, and Flow: B; each flow always appeared on a left or right page, and adding new content automatically flowed A content to a new A page, and new B content to a B page. The usual purpose was an instructor's version of a manual with the instructor's material on one page and the student material on a facing page, and each flow of conditionalized content could be shown or hidden without displacing the other. The trick was also employed to use auto-numbered paragraphs to simulate page numbers, so that the pages of each flow were identical. The bug was fixed around FM version 5 or 6, so that strategy became extinct.
    One alternate strategy that could work for your design - one inserted non-flowing page at a given location - is to create from individual files. One set of files would be the single page instructor materials. The other set of files would be created by breaking the student content into appropriate chunks of pages. Add the files to the book in the order you need. Manually restart the page numbering for each file in the book to suit your needs.
    An alternate strategy would be to redesign the pages with a wide column for student material, and a narrow column for instructor material; each column is an independent text frame with a different text flow. Showing or hiding the instructor material will not affect the flow of the student material. A similar strategy would be to use two text frames on one page; the upper one covering most of the page, and the lower one covering a smaller part of the page.
    HTH
    Regards,
    Peter Gold
    KnowHow ProServices

Maybe you are looking for

  • Acrobat XI on Win8.1 asks for Flash to create a Pdf Portfolio?

    I've been running Acrobat X for a year or so and have created many pdf portfolios, but recently installed a trial version of Acrobat XI on my Windows 8.1 PC.  I then tried to create a portfolio from scratch, selected the files and got a message "To v

  • Which compact camera wirelessly links to iPhoto

    I am looking to buy a small wifi compact camera which will send images directly from the camera to my MacBook Pro using iPhoto and also sending them to my iPod. Many such cameras link to a PC but I can't see any which link directly to a MacBook. Can

  • Performance configuration PRD system SCM 5.1 Solaris 10

    Hi! I am trying to configure some performance parameters on a PRD system that is running under a Solaris 10 machine. This system have 40CPU and 40GB RAM. SAP system = SAP SCM 5.10 I have given the sap system 15 GB and Oracle 20GB and OS = 5GB I am no

  • Zen touch: upload yes, but downlo

    hi, i want to buy a zen touch 20gb device. i've read something about it on the net, but there's one question left: . can i transfer files from my player back to my pc? 2. can i transfer audio files only or are all filetypes possible? thanks cyte

  • Repository Database shows at wrong version in Grid Control

    Hi all, I have successfully installed Grid Control and have upgraded the repository database to version 10.2.0.3. When I log into sqlplus to check the version number fit shows 10.2.0.3, but when I look at the database in Grid Control it is displaying