使用MyBatis的SQL异常
我有个问题。运行此MyBatis时,请选择:使用MyBatis的SQL异常,sql,oracle,mybatis,dao,Sql,Oracle,Mybatis,Dao,我有个问题。运行此MyBatis时,请选择: <select id="findIdByCode" resultType="long"> select USER_ID from PWD_REST_CODE where RESTORATION_CODE = #{code} and current_date between date_from and DATE_FROM + interval #{interval} second </s
<select id="findIdByCode" resultType="long">
select USER_ID from PWD_REST_CODE
where RESTORATION_CODE = #{code}
and current_date between date_from and DATE_FROM + interval #{interval} second
</select>
代表SQL命令未正确结束
但当我在数据库管理器中运行完全相同的查询时:
select USER_ID from PWD_REST_CODE
where RESTORATION_CODE = '217799dfHj'
and current_date between date_from and DATE_FROM + interval '86400' second
我得到了应得的用户id,5。为什么会发生这种情况?正如Marmite Bomber在评论中正确写道的那样,您不能在间隔文字中使用数字。使用numToDSInterval函数将数字转换为间隔:
<select id="findIdByCode" resultType="long">
select USER_ID from PWD_REST_CODE
where RESTORATION_CODE = #{code}
and current_date between date_from
and DATE_FROM + numToDSInterval( #{interval}, 'second' )
</select>
间隔“86400”秒与MyBasic中使用的间隔86400秒略有不同。我想,因为类型是NUMBER MyBatis,所以不会在其周围添加引号。
<select id="findIdByCode" resultType="long">
select USER_ID from PWD_REST_CODE
where RESTORATION_CODE = #{code}
and current_date between date_from
and DATE_FROM + numToDSInterval( #{interval}, 'second' )
</select>