mybatis oracle分页sql

以前在写oracle分页时的sql是:

(1)

select *
    from  (select a.*, rownum rnum
     from (select id, data
     from t  order by id, rowid) a
    )
   where rnum >= 148 and rnum<=151;

或者

(2)
select *
    from  (select a.*, rownum rnum
     from (select id, data
     from t  order by id, rowid) a
    where rownum <= 151 )
   where rnum >= 148;

最近在开发中同事说第(1)种效率不好,而第(2)种在只有唯一值(列)的时间才能正常排序,以前一直用第(1)种,今天同事找到如下的方式,解决了 第(2)种唯一值(列)排序的问题,如下:

(3)

select *
    from  (select a.*, rownum rnum
     from (select id, data
     from t  order by id, rowid) a
    where rownum <= 151 )
   where rnum >= 148;

PS:主要是添加了rowid这个字段。

参考网站:http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-086197.html

时间: 2024-11-07 20:36:58

mybatis oracle分页sql的相关文章

ORACLE分页SQL

1,使用rownum SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM TABLE_NAME) A WHERE ROWNUM <= 40 ) WHERE RN >= 21 2,使用between SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM TABLE_NAME) A ) WHERE RN BETWEEN 21 AND 40 ORACLE分页SQL,布布扣,b

mybatis oracle 分页+模糊查询

实现分页的方式有很多,但常用的是通过SQL来显示分页. 下面就来介绍mybatis 来实现Oracle分页的写法:(ps:不同数据库的写法有区别) 一.分页数据: 1 <select id="findPageByCode" parameterType="java.util.Map" resultMap="pageVO"> 2 select * from 3 ( 4 select A.* ,ROWNUM rn 5 from (selec

在mybatis 采用mapping文件 中的 oracle分页 SQL 配置在一个公用mapping中供后面引入使用

1.在mybatis的公共mapping中添加下面设置 三层嵌套方式和用 row_number的方式都能到达效果,但是性能优劣众说纷纭我没亲自测试过. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-m

mybatis oracle java.sql.SQLException: 流已被关闭问题

/** * 按照页码取值(从current_page页开始,每页page_size条) * @param key * @param params * @param current_page * @param page_size * @return */ public <T> Pagination getPaginationByPage(String key, Object params,int current_page,int page_size) { int count = (Integer

ORACLE 分页SQL

这个sql的分页很简单,但是由于十分常用,且通常用于查询大量数据的情况. SELECT * FROM( SELECT A.*,ROWNUM RN FROM (SELECT * FROM TABLE_XX ) A WHERE ROWNUM<=20 )  TL WHERE RN >=11 这个sql高效的原因在于优化模式下, Oracle可以将外层的查询条件推到内层查询中,以提高内层查询的执行效率. 故此查询中,查询条件WHERE ROWNUM<=20就可以被Oracle推入到内层查询中,

springmvc+mybatis 做分页sql 语句

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="ssmy.dao.UserDao"> <r

ORACLE分页SQL语句三种分页技术

1.根据ROWID来分select * from t_xiaoxi where rowid in(select rid from (select rownum rn,rid from(select rowid rid,cid from t_xiaoxi  order by cid desc) where rownum<10000) where rn>9980) order by cid desc;执行时间0.03秒 2.按分析函数来分select * from (select t.*,row_

oracle分页sql语句

select * from(select a1.*, rownum.rn from(select *from emp) a1 where rownum<=10) where rn>=6; select * from(select a1.*, rownum.rn from(select *from emp) a1 where rownum<=10) where rn>=6;

ORACLE分页SQL语句(转载)

1.根据ROWID来分select * from t_xiaoxi where rowid in(select rid from (select rownum rn,rid from(select rowid rid,cid from t_xiaoxi  order by cid desc) where rownum<10000) where rn>9980) order by cid desc;执行时间0.03秒2.按分析函数来分select * from (select t.*,row_n