用Mybatis框架执行的结果和自己执行的结果不一致。

Lzz8658 Lzz8658 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
用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条数据。
...全文
评论 10
收藏 已收藏
分享
返回顶部
Lzz8658
基础和管理 17,377 成员 95,111 内容