我想将所有以 https://oneweburl.com/cm
开头的 URL 替换为 https://anotherwebsite.com
即诸如
之类的网址https://oneweburl.com/cm/9304/434
https://oneweburl.com/cm/849/495/34
https://oneweburl.com/cm/2994/234/54
将仅替换为 https://anotherwebsite.com
。到目前为止,我已经尝试过了
update wp_posts
set post_content =
replace(post_content, 'https://oneweburl.com/cm/%', 'https://anotherwebsite.com');
显然这没有用。知道用 SQL 来完成这个吗?谢谢!
最佳答案
在大多数情况下,您应该能够:
update wp_posts
set post_content = replace(post_content, 'https://oneweburl.com/cm/', 'https://anotherwebsite.com/')
where post_content like 'https://oneweburl.com/cm/%';
这应该适用于任何数据库。
一个问题是 post_content
是否可以在字符串中包含多个 URL。这将替换指定字符串的所有匹配项。如果这是一个问题,您可以进行字符串操作来做正确的事情。 las,这些往往取决于特定的数据库。
关于mysql - 如何替换sql中的通配符url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48632142/