mybatis运行sql出错,单独在数据库中运行正常,不解

Zoopra 2017-03-01 06:05:04
原sql语句:
select
c.id id,
c.content content,
c.commentDate commentDate,
c.article_id articleId,
c.visitor_id visitorId,
v.nickname nickname,
v.email email,
v.sex sex,
(case
length(queryCommentWithAmout(c.id))-length(replace(queryCommentWithAmout(c.id),',',''))
when
0
then
0
else
length(queryCommentWithAmout(c.id))-length(replace(queryCommentWithAmout(c.id),',',''))+1
end)
replyCount
from t_comment c left join visitor v
on c.visitor_id = v.id
where c.article_id =#{articleId} and c.comment_id is null
group by c.id
order by commentDate DESC

在数据库中执行的结果



mybatis上运行后台报错:

### The error may involve net.code.train.dao.CommentMapper.selectByArticleId-Inline
### The error occurred while setting parameters
### java.sql.SQLException: Illegal mix of collations (utf8_unicode_ci,COERCIBLE), (utf8_general_ci,COERCIBLE), (utf8_general_ci,COERCIBLE) for operation 'replace'

我后来把参数直接给定一个常数为10,仍然报相同的错误,不明白错误出自哪?sql里调用的函数是自定义的,已测试可以正常运行。
...全文
563 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
小丫头煜 2019-03-11
  • 打赏
  • 举报
回复
可能是get set方法写错了
Zoopra 2017-03-02
  • 打赏
  • 举报
回复
引用 1 楼 pany1209 的回复:
编码问题?。。。。输入字符是全角或半角?
问题我找到了,在调用replace函数时,三个参数的编码不一,其中第一个参数是我自定义的函数,返回值varchar,编码utf8_unicode_ci。后两个参数编码utf8_general_ci,产生冲突。于是我将第一个参数CONVERT(queryCommentWithAmout(c.id) USING utf8)使用该方法转换,可以正常运行了。
李德胜1995 2017-03-01
  • 打赏
  • 举报
回复
编码问题?。。。。输入字符是全角或半角?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧