错误代码:1267。操作“=”的排序规则(utf8_general_ci,IMPLICIT)和(utf8_unicode_ci,IMPLICIT)的非法混合

Posted

技术标签:

【中文标题】错误代码:1267。操作“=”的排序规则(utf8_general_ci,IMPLICIT)和(utf8_unicode_ci,IMPLICIT)的非法混合【英文标题】:Error Code: 1267. Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '=' 【发布时间】:2016-02-19 21:27:04 【问题描述】:

我们正在使用以下存储过程,并且所有提到的表都使用“Collat​​ion = utf8_general_ci”我们仍然收到此错误:

错误代码:1267。操作 '=' 的排序规则 (utf8_general_ci,IMPLICIT) 和 (utf8_unicode_ci,IMPLICIT) 的非法混合

存储过程是:

    DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `AssignCallRates`()
begin
    declare countrycode varchar(8000);
        declare countryname varchar(8000);
        declare currencycode    varchar(8000);
        declare priceval    varchar(8000);
        declare mobileprice varchar(8000);
        declare landprice   varchar(8000);
        declare reccnt      int;
        DECLARE done INT DEFAULT FALSE;
        declare country_cursor cursor for select country_code,country_name from dialoone_countries;
        declare aud_cursor cursor for select convert(price,char) as price from tbl_rate_aud where quick_search=1 and trim(substring_index(`place`,'-',1)) = countryname LIMIT 0,2;
        declare euro_cursor cursor for select convert(price,char) as price from tbl_rate_euro where quick_search=1 and trim(substring_index(`place`,'-',1)) = countryname LIMIT 0,2;
        declare gbp_cursor cursor for select convert(price,char) as price from tbl_rate_gbp where quick_search=1 and trim(substring_index(`place`,'-',1)) = countryname LIMIT 0,2;
        declare usd_cursor cursor for select convert(price,char) as price from tbl_rate_dollar where quick_search=1 and trim(substring_index(`place`,'-',1)) = countryname LIMIT 0,2;
        declare continue handler for not found set done=TRUE;

        truncate table tbl_rates;

        open country_cursor;
        CountryLOOP: loop
            fetch country_cursor into countrycode,countryname;
                if done=TRUE then
                    close country_cursor;
                    leave CountryLOOP;
                end if;
                set mobileprice = "";
                set landprice="";
                set reccnt = 0;
                set priceval = "";
                open aud_cursor;
                AUDLOOP: loop
                    fetch aud_cursor into priceval;
                        if done = TRUE then
                            set done = FALSE;
                            close aud_cursor;
                            leave AUDLOOP;
                        end if;
                        set reccnt = reccnt + 1;
                        if reccnt = 1 then
                            set landprice=priceval;
                        end if;
                        if reccnt = 2 then
                            set mobileprice=priceval;
                        end if;
        end loop AUDLOOP;
                insert into tbl_rates (country_code,currency_code,mobile,land) values (countrycode,"AUD",mobileprice,landprice);

                set mobileprice = "";
                set landprice="";
                set reccnt = 0;
                set priceval = "";
                open euro_cursor;
                EUROLOOP: loop
                    fetch euro_cursor into priceval;
                        if done = TRUE then
                            set done = FALSE;
                            close euro_cursor;
                            leave EUROLOOP;
                        end if;
                        set reccnt = reccnt + 1;
                        if reccnt = 1 then
                            set landprice=priceval;
                        end if;
                        if reccnt = 2 then
                            set mobileprice=priceval;
                        end if;
        end loop EUROLOOP;
                insert into tbl_rates (country_code,currency_code,mobile,land) values (countrycode,"EUR",mobileprice,landprice);

                set mobileprice = "";
                set landprice="";
                set reccnt = 0;
                set priceval = "";
                open gbp_cursor;
                GBPLOOP: loop
                    fetch gbp_cursor into priceval;
                        if done = TRUE then
                            set done = FALSE;
                            close gbp_cursor;
                            leave GBPLOOP;
                        end if;
                        set reccnt = reccnt + 1;
                        if reccnt = 1 then
                            set landprice=priceval;
                        end if;
                        if reccnt = 2 then
                            set mobileprice=priceval;
                        end if;
        end loop GBPLOOP;
                insert into tbl_rates (country_code,currency_code,mobile,land) values (countrycode,"GBP",mobileprice,landprice);

                set mobileprice = "";
                set landprice="";
                set reccnt = 0;
                set priceval = "";
                open usd_cursor;
                USDLOOP: loop
                    fetch usd_cursor into priceval;
                        if done = TRUE then
                            set done = FALSE;
                            close usd_cursor;
                            leave USDLOOP;
                        end if;
                        set reccnt = reccnt + 1;
                        if reccnt = 1 then
                            set landprice=priceval;
                        end if;
                        if reccnt = 2 then
                            set mobileprice=priceval;
                        end if;
        end loop USDLOOP;
                insert into tbl_rates (country_code,currency_code,mobile,land) values (countrycode,"USD",mobileprice,landprice);
    end loop CountryLOOP;
    select "Query Executed Successfully";       
end$$
DELIMITER ;

需要对此 SP 进行任何更新吗?

【问题讨论】:

【参考方案1】:

From other answer: 存储过程参数的默认排序规则是 utf8_general_ci 并且您不能混合排序规则,这意味着数据库/表可能是 unicode。

先试试这个:

SELECT @@collation_database;

然后查看您正在使用的实际表的 CREATE 语句。

More Info

【讨论】:

以上是关于错误代码:1267。操作“=”的排序规则(utf8_general_ci,IMPLICIT)和(utf8_unicode_ci,IMPLICIT)的非法混合的主要内容,如果未能解决你的问题,请参考以下文章

MySQL某些字符导致“非法混合排序规则”错误

排序规则的非法混合 MySQL 错误

操作“=”的排序规则的非法混合

操作'='的排序规则(utf8mb4_unicode_ci,IMPLICIT)和(utf8mb4_general_ci,IMPLICIT)的错误混合

mysql字符集问题 错误代码: 1267 Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_croatian_ci,IM

Jira中的Mysql错误“操作'='的排序规则(latin1_swedish_ci,I MPLICIT)和(utf8_general_ci,COERCIBLE)的非法混合”[重复]