[英]How to replace Wildcard url in sql?
I want to replace all URLs that start with https://oneweburl.com/cm
with https://anotherwebsite.com
我想将所有以https://oneweburl.com/cm
开头的URL替换为https://anotherwebsite.com
ie URLs such as 即网址,例如
https://oneweburl.com/cm/9304/434
https://oneweburl.com/cm/849/495/34
https://oneweburl.com/cm/2994/234/54
will be replaced with only https://anotherwebsite.com
. 将仅替换为https://anotherwebsite.com
。 So far I have tried 到目前为止,我已经尝试过
update wp_posts
set post_content =
replace(post_content, 'https://oneweburl.com/cm/%', 'https://anotherwebsite.com');
Apparently that didn't work. 显然那没有用。 Any idea the SQL to accomplish this? 知道用SQL完成此操作吗? Thanks! 谢谢!
For the most part, you should be able to do: 在大多数情况下,您应该能够:
update wp_posts
set post_content = replace(post_content, 'https://oneweburl.com/cm/', 'https://anotherwebsite.com/')
where post_content like 'https://oneweburl.com/cm/%';
This should work in any database. 这应该可以在任何数据库中使用。
The one issue is if post_content
could have multiple URLs in the string. 一个问题是post_content
是否可以在字符串中包含多个URL。 This will replace all matches to the specified string. 这会将所有匹配项替换为指定的字符串。 If that is an issue, you can do string manipulations to do the right thing. 如果这是一个问题,则可以进行字符串操作以执行正确的操作。 Alas, those tend to depend on the specific database. las,那些往往依赖于特定的数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.