mysql - 如何替换sql中的通配符url?

标签 mysql sql

我想将所有以 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/

相关文章:

sql - 在 Stata 中创建和使用临时/ volatile 数据库表

python - 如何使用 Django 的 index_together 与 filter 和 order_by 一起查询?

mysql - 满足3NF的数据库设计

mysql - 根据先前的选择结果优化选择行

mysql - 在 mySQL 中连接今天和昨天的列

sql - 删除单个服务器上的所有 SQL Server 链接服务器

c# - 将 ADO.Net 实体数据模型向导连接到 MySQL 数据库

php - MySQL一对多关系,具有共享值

php - MySQL 日期比较返回 null

sql - 如何从 SSMS 获取完整结果集