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有效!

PS:

  基础真的非常重要!!

  再简单的代码也要多敲几遍,这样才“有可能“成为你的一部分”!

posted @ 2019-08-29 19:42  Arebirth  阅读(7379)  评论(0编辑  收藏  举报