1.场景描述
我的 mapper.xml文件中查询Oracle数据的写法如下:
<select id="selectCountBetweenTime" parameterType="java.util.Map" resultType="int">
select count(*) from CHAIN_ORDER where
SELLER_NAME LIKE CONCAT('%', #{platform, jdbcType=VARCHAR}, '%')
<![CDATA[and PAY_TIME >= #{beginTime, jdbcType=TIMESTAMP}
and PAY_TIME < #{endTime, jdbcType=TIMESTAMP}]]>
</select>
2.故障现象
2019-06-21 17:54:18.722 [ERROR] [Saturn-OrderCountMonitorJob-14-thread-1] druid.sql.Statement [statementLogError-149] -{conn-10010, pstmt-20000} execute error. select count(*) from CHAIN_ORDER where
SELLER_NAME LIKE CONCAT('%', ?, '%')
and PAY_TIME >= ?
and PAY_TIME < ?
java.sql.SQLSyntaxErrorException: ORA-00909: 参数个数无效
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
3.问题分析
oracle中不支持concat的三个参数的拼接。
4.解决方案
select * from SYS_MENU where url like concat(concat(‘%’,#{roleName}),’%’)
或者
select * from SYS_MENU where url like ‘%’ || #{roleName} || ‘%’;