MySQL 在 LOCATE 中使用用户定义的变量时出现非法混合排序规则

MySQL Illegal mix of collations when using user-defined variables inside LOCATE

我有一个如下所示的查询,用于从 table 列中删除某些以特定子字符串开头和结尾的子字符串:

UPDATE om_posts SET post_content=REPLACE(post_content, SUBSTRING(
    post_content, 
    LOCATE(' style="', post_content), 
    LOCATE('"', post_content, LOCATE(' style="', post_content  )+ 8) - LOCATE(' style="', post_content ) + 1
),'')
where post_type="post";

我想让它更好地重用,所以我想抽象出那些字符串。我在 mysql 中遇到了用户定义的变量并像这样重构:

SET @beginning = ' style="';
SET @ending ='"';

UPDATE om_posts SET post_content=REPLACE(post_content, SUBSTRING(
    post_content, 
    LOCATE(@beginning, post_content), 
    LOCATE(@ending, post_content, LOCATE(@beginning, post_content  )+ 8) - LOCATE(@beginning, post_content ) + 1
),'')
where post_type="post";

但这给出了一个错误:Error in query (1267): Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation 'locate'。据我所知,我的语法应该是正确的。我错过了什么?

Every character string literal has a character set and a collation.

For the simple statement SELECT 'string', the string has the connection default character set and collation defined by the character_set_connection and collation_connection system variables.

A character string literal may have an optional character set introducer and COLLATE clause, to designate it as a string that uses a particular character set and collation:

[_charset_name]'string' [COLLATE collation_name]

来自 official documentation

该页面的示例:_utf8mb4'abc' COLLATE utf8mb4_danish_ci