为了能在查询时忽略字段大小写,又不想修改数据表的属性配置,就在SQL语句中做了修改。结果在alibaba druid 执行时报错

com.alibaba.druid.sql.parser.ParserException: syntax error, error in :'ame  collate 'utf8mb4_general_ci' f', expect RPAREN, actual LITERAL_CHARS pos 166, line 1, column 147, token LITERAL_CHARS utf8mb4_general_ci

这个错误在sql的命令行执行没有问题,但是druid 会解析失败,原因是collate用错了地方,只能用在where的查询条件里。

select app.id,app.token,app.email,app.retry,app.interval_time,app.user_id,app.update_time,app.create_time,app.name 
from app 
inner join user on app.user_id=user.id 
where app.name collate 'utf8mb4_general_ci' like CONCAT('%',#{name,jdbcType=VARCHAR},'%') or user.department like CONCAT('%',#{name,jdbcType=VARCHAR},'%') order by app.create_time desc,app.name

 

 posted on 2019-04-03 16:49  ChaseForFuture  阅读(695)  评论(0编辑  收藏  举报