码迷,mamicode.com
首页 > 数据库 > 详细

Java中oracle分页查询01

时间:2019-06-04 14:52:20      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:mybatis   val   dict   inno   aaa   rownum   creat   分页   country   

在数据库汇中的查询语句:oracle中使用rownum进行分页,从每页在总记录数的第n条到第m条;这里的是每页10条记录,下面sql所查询的是第页的记录数;oracle的分页是从1开始的,这里写成rownum>=0,rownum<=9,查询的记录是9条。

SELECT * FROM (SELECT ROW_.*, ROWNUM ROWNUM_
          FROM (SELECT *
                  FROM TABLE1
                 WHERE TABLE1_ID = XX
                 ORDER BY GMT_CREATE DESC) ROW_
         WHERE ROWNUM <= 20)
 WHERE ROWNUM_ >= 11;

一般项目从页面传递的数据是:page,pagesize;写成sql语句:

select * from (select rownum rn,a.* from A_MODEL a where rownum<=page*pageSize)aa where aa.rn>(page-1)*pageSize

下面是在实际项目的一条sql语句:值得注意的是在mybatis中不能用<,而要用转义字符(&lt;)

<select id="queryLossModelList" resultMap="BaseResultMap">
        SELECT aaa.*,s.MIN_NAME FROM (SELECT aa.*
        FROM
        (SELECT rownum rn,a.*
        FROM A_MODEL_LOSS a
        WHERE 1=1
        <choose>
            <when test="cateId != null and cateId != ‘‘">
                and a.model_cate_id in (select cate_id from a_category c where c.cate_id = #{cateId})
            </when>
            <when test="brandId != null and brandId != ‘‘">
                and a.model_cate_id in
                (select cate_id from a_category bc where bc.cate_parent_id = #{brandId})
            </when>
            <when test="factoryId != null and factoryId != ‘‘">
                and a.model_cate_id in
                (select cate_id from a_category bc
                where bc.cate_parent_id in
                (select cate_id from a_category fc where fc.cate_parent_id = #{factoryId}))
            </when>
        </choose>
        <if test="country != null and country != ‘‘">
            and a.MODEL_COUNTRY = #{country}
        </if>
        <if test="standardName != null and standardName != ‘‘">
            and a.MODEL_STANDARD_NAME LIKE %${standardName}%
        </if>
        <if test="vinNo != null and vinNo !=‘‘">
            and a.MODEL_VIN_NO LIKE %${vinNo}%
        </if>
        and rownum &lt;= #{endRow})aa
        WHERE aa.rn > #{startRow})aaa LEFT JOIN S_DICT_MIN s on aaa.MODEL_CLASS = s.MIN_VALUE
    </select>

Java中oracle分页查询01

标签:mybatis   val   dict   inno   aaa   rownum   creat   分页   country   

原文地址:https://www.cnblogs.com/lazyli/p/10973403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!