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

标签 mysql stored-procedures

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

Error Code: 1267. Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='

存储过程是:

    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 需要更新吗?

最佳答案

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

首先尝试这个:

SELECT @@collation_database;

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

More Info

关于mysql - 错误代码 : 1267. 操作 '=' 的排序规则 (utf8_general_ci,IMPLICIT) 和 (utf8_unicode_ci,IMPLICIT) 的非法混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33775062/

相关文章:

mysql - mySQL 的外键

database - 使用来自 mysql 转储的授权填充 mysql 数据库

Mysql存储过程在某些行后停止迭代

mysql - 触发器声明内的局部变量存在语法错误

PostgreSQL:在一个函数中插入、删除和更新的 If Else 语句

Java:调用存储过程时出现 mysql 错误

java - 当用java访问网页时,我的php页面的主体变成关于javascript的错误

mysql - 我应该在 MySQL 中使用 SMALLINT 而不是 DATETIME 来节省空间吗?

php - 无法访问 CodeIgniter 站点

sql - 将值拆分为多行