sql报错Illegal mix of collations

select company_name from upload_record_detail where company_name in ('晋县高贤纸箱𠂆_否_是','邢台欧乐建筑工程有限公司_否_是')

查询报错:

[HY000][1270] Illegal mix of collations (utf8_general_ci,IMPLICIT), (utf8mb4_0900_ai_ci,COERCIBLE), (utf8mb4_0900_ai_ci,COERCIBLE) for operation ' IN '

修改为:

select company_name from upload_record_detail where
    company_name in (
    <foreach collection="list" item="obj" separator=",">
      #{obj} COLLATE utf8mb4_0900_ai_ci
    </foreach>
    ) and del_flag = 0

报错

MySql报 java.sql.SQLException: Incorrect string value 乱码解决方法

修改字符集 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在执行SQL语句时,如果比较两个表的字段时出现了"Illegal mix of collations"错误,这意味着比较的两个字段的字符集不一致。具体地说,一个字段的字符集是utf8mb4_general_ci,而另一个字段的字符集是utf8mb4_unicode_ci。这个错误会导致"="操作无法进行。为了解决这个问题,有几个方法可以尝试: 1. 在查询时进行数据类型转换,使用CONVERT函数将字段的字符集转换为一致的utf8mb4_unicode_ci。例如,可以使用以下语句进行转换: CONVERT(column_name USING utf8mb4) COLLATE utf8mb4_unicode_ci 2. 将两个表的字符集保持一致。可以使用ALTER TABLE语句将表的字符集修改为utf8mb4_general_ci。例如,可以使用以下语句进行修改: ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci 以上是解决"Illegal mix of collations"错误的两种常见方法。通过执行这些方法,您可以确保比较的字段具有相同的字符集,从而避免出现错误。希望对您有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [mysql字段编码不一致导致Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_...](https://blog.csdn.net/chen417980762/article/details/127068037)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [MYSQL查询报错Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT)](https://blog.csdn.net/weixin_44729970/article/details/122099794)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值