Java,J2EE,Weblogic,Oracle

java项目随笔
随笔 - 90, 文章 - 6, 评论 - 61, 引用 - 0
数据加载中……

Oracle分页的两种方式

第一种:
select b.*
  from (select rownum as rid, a.* from om_cm_book_hotword a) b
 where b.rid <= 10
   and b.rid > 5;

第二种:
select c.*
  from (select rownum as rid, b.*
          from (select a.* from om_cm_book_hotword a) b
         where rownum <= 10) c
 where rid > 5


因为rownum 的位置不同,第二种相对于第一种增加了一层嵌套查询。


举例:
select *
     from (select rownum as rid, b.*
             from (select *
                     from T_MEMBERIMPORT a
                    where a.importdate <=
                          to_date(#enddate#, 'yyyy/MM/dd hh24:mi:ss')
                      and a.importdate >=
                          to_date(#begindate#, 'yyyy/MM/dd hh24:mi:ss')) b
            where rownum <= #PageNow# * 10) c
    where rid > (#PageNow#  - 1) * 10   


 <select id="queryVvip" parameterClass="java.util.Map" resultMap="businesstravel.VvipResult">
   select *
     from (select rownum as rid, b.*
             from (select * from t_vvip
           <isNotEmpty prepend="where" property="name">
                  name=#name#
     </isNotEmpty>
     <isNotEmpty prepend="and" property="companyname">
                  companyname=#companyname#
           </isNotEmpty>
              order by id     ) b
            where  #PageNow# * 10>= rownum ) c
    where rid > (#PageNow#  - 1) * 10     
  </select>

posted on 2007-03-13 15:52 龚椿深 阅读(389) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: