mysql 字符串=比较 Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_gene

本文介绍了MySQL中因字符串比较导致的错误:'Illegal mix of collations',并提供了解决方案,通过使用CONVERT函数来统一字符串的字符集和排序规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MySQL进行字符串比较时发生错误:

SELECT
	a.equ_no,
	b.fullCode
FROM
	equipment a,
	(
		SELECT
			t.*, getEquTypeFullCode (t.equType_id) AS fullCode
		FROM
			equ_type t
	) b
WHERE
	substring(a.equ_no, 1, 5) = b.fullCode

 错误如下: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='

解决方法:将比较等式一边进行字符串转换,如改为“CONVERT(b.fullCode USING utf8) COLLATE utf8_unicode_ci

 

UPDATE template_messag_doctor a SET a.sended=1 where  EXISTS (select 1 from template_messag_exclude_openid b where a.openid = CONVERT(b.openid USING utf8) COLLATE utf8_unicode_ci  ) 

 

SELECT
	a.equ_no,
	b.fullCode
FROM
	equipment a,
	(
		SELECT
			t.*, getEquTypeFullCode (t.equType_id) AS fullCode
		FROM
			equ_type t
	) b
WHERE
	substring(a.equ_no, 1, 5) = CONVERT(b.fullCode USING utf8) COLLATE utf8_unicode_ci;

 

UPDATE template_messag_doctor a SET a.sended=1 where  EXISTS (select 1 from template_messag_exclude_openid b where a.openid = CONVERT(b.openid USING utf8) COLLATE utf8_unicode_ci  ) 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值