用Mybatis框架执行的结果和自己执行的结果不一致。
下面是Mybatis的配置
<select id="selectNoteByPage" parameterType="com.bean.Page" resultMap="NoteResultMap">
(select *
from (select * from bbs.bbsnote order by responsedate desc)
where rownum <![CDATA[<=]]> #{maxnum})
minus
(select *
from (select * from bbs.bbsnote order by responsedate desc)
where rownum <![CDATA[<=]]> #{minnum})
</select>
执行结果:
DEBUG [http-bio-8888-exec-1] - Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4e69f6b0]
DEBUG [http-bio-8888-exec-1] - JDBC Connection [oracle.jdbc.driver.T4CConnection@19de40b4] will be managed by Spring
DEBUG [http-bio-8888-exec-1] - ==> Preparing: (select * from (select * from bbs.bbsnote order by responsedate desc) where rownum <= ?) minus (select * from (select * from bbs.bbsnote order by responsedate desc) where rownum <= ?)
DEBUG [http-bio-8888-exec-1] - ==> Parameters: 15(Integer), 10(Integer)
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 51(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 22
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 71(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 1
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 91(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 2
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 223(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 25
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 303(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 1
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 338(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 5
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 351(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 12
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 353(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 0
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 354(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 1
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 355(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 2
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 484(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 0
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 522(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 0
DEBUG [http-bio-8888-exec-1] - ====> Preparing: select * from BBS.BBSNOTESOFA where NOTEID=?
DEBUG [http-bio-8888-exec-1] - ====> Parameters: 540(Long)
DEBUG [http-bio-8888-exec-1] - <==== Total: 0
DEBUG [http-bio-8888-exec-1] - <== Total: 13
上面得到的结果不是我想要的,居然有13条数据,搞不懂这时为什么,但是我自己来执行sql,结果却是正确的,我真的找不出问题点了:
(select *
from (select * from bbs.bbsnote order by responsedate desc)
where rownum <=15)
minus
(select *
from (select * from bbs.bbsnote order by responsedate desc)
where rownum <=10);
这里执行结果是正确的,
5条数据。