使用正则表达式使用MySQL编辑整个列

时间:2013-05-03 02:59:43

标签: mysql sql regex

我有一张这样的表:

| link  |
----------
http://dev.example.com/images/image1.png
http://dev.example.com/images/image2.png
http://dev.example.com/images/image3.png
http://dev.example.com/images/image4.png

但是,我需要更改它,因此它包含:

| link  |
----------
http://example.com/resources/images/image1.png
http://example.com/resources/images/image2.png
http://example.com/resources/images/image3.png
http://example.com/resources/images/image4.png

有很多条目需要改变。更新所有条目的好方法是什么?

现在我正在使用它来查找条目:

SELECT column
FROM table
WHERE link REGEXP '^dev'

我首先手动更新链接,但还剩下很多。我不能自己更新它们。

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

你在表列表中将其称为“字段”,但在SQL中将其称为“链接”,因此我将使用“字段”

update table 
set 
    Field = replace(Field, 'dev.site.com', 'site.com/resources') 
where 
    Field rlike '^dev.site.com'
相关问题