gpt4 book ai didi

mysql - 更新路径行中域名的sql语句

转载 作者:行者123 更新时间:2023-11-29 00:52:07 25 4
gpt4 key购买 nike

假设这张表

+--------------+---------------------------------+
| id | path |
+--------------+---------------------------------+
| 1 | http://old.com/img/1.png |
| 2 | http://old.com/img/2.png |
| 3 | http://old.com/img/3.png |
| 4 | http://old.com/img/4.png |
| 5 | http://old.com/img/5.png |
| 6 | http://old.com/img/6.png |
+--------------+---------------------------------+

什么句子会更新成

+--------------+---------------------------------+
| id | path |
+--------------+---------------------------------+
| 1 | http://new.com/img/1.png |
| 2 | http://new.com/img/2.png |
| 3 | http://new.com/img/3.png |
| 4 | http://new.com/img/4.png |
| 5 | http://new.com/img/5.png |
| 6 | http://new.com/img/6.png |
+--------------+---------------------------------+

我不知道如何在 mysql 中进行 str_replace

“UPDATE table SET path = REPLACE(path, 'old.com', 'new.com')” ??我不能在这里弄乱数据库..

最佳答案

update mytable set path = replace(path, 'old.com', 'new.com');

如果您担心更新的影响(您应该担心),我首先这样做:

select path, replace(path, 'old.com', 'new.com') as new_path
from mytable;

我只是观察结果,看它们是否“看起来不错”。如果他们这样做,则触发更新。

关于mysql - 更新路径行中域名的sql语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8063061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com