sql替换十六进制字符串

cx6n0qe3  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(2074)

我在一个阿拉伯语(wordpress)网站上工作,有成千上万的帖子,需要搜索和替换帖子内容中的一些链接,但得到的结果不一致,我想可能是因为我搜索的字符串是阿拉伯语单词的十六进制版本。例如,在本例中,我要搜索 team/ليفربول 并用 team/liverpool 但我真的要找 %D9%84%D9%8A%D9%81%D8%B1%D8%A8%D9%88%D9%84 哪个是ليفربول (利物浦)十六进制。
选择返回预期的~300个结果:

SELECT * FROM `wp_posts` WHERE `post_content` LIKE '%/team/%D9%84%D9%8A%D9%81%D8%B1%D8%A8%D9%88%D9%84%'

但是,当我对updatesql查询执行一个空运行时,它返回0个受影响的行,而不是预期的~300。

UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`, '/team/%D9%84%D9%8A%D9%81%D8%B1%D8%A8%D9%88%D9%84', '/team/liverpool') WHERE `post_content` LIKE '%/team/%D9%84%D9%8A%D9%81%D8%B1%D8%A8%D9%88%D9%84%';

我怀疑sql与 % 字符串中的字符,我想知道是否需要以某种方式对整个字符串进行转义,以便sql不将它们视为通配符,而是按它们的外观来处理。

qybjjes1

qybjjes11#

试一试:

UPDATE wp_posts SET post_content = REPLACE (post_content, 'team/ليفربول', 'team/liverpool');
UPDATE wp_posts SET post_excerpt = REPLACE (post_excerpt, 'team/ليفربول', '/team/liverpool');
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'team/ليفربول','/team/liverpool');
UPDATE wp_termmeta SET meta_value = REPLACE (meta_value, 'team/ليفربول','/team/liverpool');
UPDATE wp_comments SET comment_content = REPLACE (comment_content, 'team/ليفربول', '/team/liverpool');
UPDATE wp_comments SET comment_author_url = REPLACE (comment_author_url, 'team/ليفربول','/team/liverpool');
UPDATE wp_posts SET guid = REPLACE (guid, 'team/ليفربول', '/team/liverpool') WHERE post_type = 'attachment';

也可能值得检查你的程序 / 不会影响你的成绩。
我能用阿拉伯字符串来匹配 post_content 通过向帖子添加超链接进行录制:

相关问题