Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '=

问题描述:MySQL进行字符串比较时发生错误:

 
  1. SELECT

  2. a.equ_no,

  3. b.fullCode

  4. FROM

  5. equipment a,

  6. (

  7. SELECT

  8. t.*, getEquTypeFullCode (t.equType_id) AS fullCode

  9. FROM

  10. equ_type t

  11. ) b

  12. WHERE

  13. substring(a.equ_no, 1, 5) = b.fullCode

错误如下:

[Err] 1267 - Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='


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

 
  1. SELECT

  2. a.equ_no,

  3. b.fullCode

  4. FROM

  5. equipment a,

  6. (

  7. SELECT

  8. t.*, getEquTypeFullCode (t.equType_id) AS fullCode

  9. FROM

  10. equ_type t

  11. ) b

  12. WHERE

  13. substring(a.equ_no, 1, 5) = CONVERT(b.fullCode USING utf8) COLLATE utf8_unicode_ci;

来源:https://blog.csdn.net/hellostory/article/details/7266447

猜你喜欢

转载自blog.csdn.net/gb4215287/article/details/81626334