Mybatis连接Oracle使用concat关键字进行模糊查询遇到的坑
在使用MyBatis操作Oracle数据库的时候,写模糊查询突然发现原本在MySql中正确的代码,在Oracle中报错,参数个数无效
<if test="empId!=null and empId!=''"> and e.empId like CONCAT('%',#{empId},'%') </if>
异常信息;
经过查阅数个资料后得知Oracle的CONCAT函数不像MySql那样支持三个参数的拼接,需要把SQL语句修正为:
and e.empId like CONCAT(CONCAT('%',#{empId}),'%')
或者
and e.empId like '%' || #{empId} ||'%';
以上仅对Oracle有效!