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

oracle分页语句

时间:2015-09-30 12:29:30      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

以Student表为例进行分页

纯sql分页

 SELECT * FROM (
       SELECT ROWNUM,A.* FROM (
            SELECT *
            FROM STUDENT ORDER BY createTime DESC
       )A WHERE ROWNUM <= 10 )
  WHERE ROWNUM >=1;

mybatis分页

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="student">
	<typeAlias alias="Student" type="com.bobo.code.model.Student" />
	<select id="select" resultClass="Student">
		SELECT * FROM
		(
			SELECT  A.*,ROWNUM 	FROM
				 (SELECT * FROM	STUDENT) A
			WHERE  <![CDATA[ ROWNUM <=  #minRownnum#]]>
		)
		WHERE  <![CDATA[ROWNUM >=   #maxRownum#]]>
	</select>

	<select id="count" resultClass="java.lang.Integer">
		SELECT count(*) FROM STUDENT
	</select>

</sqlMap>

  

		queryMap.put("minRownnum", (pageNumber - 1)*Pager.DEFAULT_PAGE_SIZE +1);//oracle rownum起
		queryMap.put("maxRownum", pageNumber * Pager.DEFAULT_PAGE_SIZE );//oracle rownum止

  

开发过程异常

无法转换为内部表示

当Student的属性id 为Integer,和数据库中的字段ID为VARCHAR2 导致不对应会取不出数据

技术分享

oracle分页语句

标签:

原文地址:http://www.cnblogs.com/whatlonelytear/p/4848552.html

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