我有一个类似下面的查询,要从表列中删除某些以特定子字符串开头和结尾的子字符串:
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'
。据我所知,我的语法应该是正确的。我错过了什么?