1. 程式人生 > >報錯:illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='

報錯:illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='

imp ner 解決方法 block wid sql cit 編碼 不知道

sql語句:

select t1.block_info, t2.zone 
from device_indoor_tbl t1 
left join blackwhitezone_tbl t2 on t1.block_info=t2.zone 

字符集編碼不同:

技術分享

技術分享

報錯信息:illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation ‘=‘

技術分享

原因:字符集編碼不同。

ps:按理說同一個數據庫的字符集編碼應該是一樣的,奈何之前不知道什麽原因數據庫竟然有不同的編碼,接手的時候數據庫又不敢亂改,只能從sql語句著手想辦法,百度了好久,最後還是問另外一個同事才解決的。

解決方法:將兩個字段的字符集編碼改成相同的。(建議修改成多數表所用的字符集編碼,我的數據庫多數表是utf8_general_ci編碼,只有少數幾張例外是utf8_unicode_ci)

修改後的sql語句:

select t1.block_info, t2.zone 
from device_indoor_tbl t1 
left join blackwhitezone_tbl t2 on t1.block_info=t2.zone COLLATE utf8_general_ci

報錯:illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='