如何解决Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (gbk_chinese_ci,IMPLICIT)的问题

来源:互联网 发布:上古卷轴5梦璃捏脸数据 编辑:程序博客网 时间:2024/06/05 03:09

在执行以下SQL语句时

sql = "select reject_id, rejectdate,rejectreason, receivedocdate, receivedoctime from rejectprj where fhbh=(selectfhbh from reviewprj where id=?) order by reject_id desc " ;

出现以下错误:

Illegal mix of collations(latin1_swedish_ci,IMPLICIT) and (gbk_chinese_ci,IMPLICIT) for operation '='错误

 

进入MySQL,分别查看rejectprj和reviewprj两个表的结构,通过show full columns from <table>,查看其Collation,如下图




其中reviewprj的fhbh为gbk_chinese_ci,而rejectprj的fhbh为latin1_swedish_ci,所以当两表通过fhbh关联时,就会出现以上错误。

 

则通过以下命令将rejectprj的fhbh的Collation更改为gbk_chinese_ci。

 

mysql>alter table rejectprj changecolumn fhbh fhbh varchar(20) character set 'gbk_chinese_ci';

 

这样修改后,执行以上SQL命令不会出错了。



0 0
原创粉丝点击