替换MySQL数据库中数据库字段中的字符串(URL)
我试图更改数据库表中多个字段中的域名,但对语法有点困惑 我需要换一张叫做面包屑的桌子 改变 在表中的每个条目中添加 当然,在域之后有一个完整的URL替换MySQL数据库中数据库字段中的字符串(URL),mysql,Mysql,我试图更改数据库表中多个字段中的域名,但对语法有点困惑 我需要换一张叫做面包屑的桌子 改变 在表中的每个条目中添加 当然,在域之后有一个完整的URL URL显示在两列中。一个简单的方法是使用两个更新: update breadcrumbs set url1 = concat('http://newurl.com', substr(url1, 18)) where url1 like 'http://oldurl.com%'; update breadcrumbs set
URL显示在两列中。一个简单的方法是使用两个更新:
update breadcrumbs
set url1 = concat('http://newurl.com', substr(url1, 18))
where url1 like 'http://oldurl.com%';
update breadcrumbs
set url2 = concat('http://newurl.com', substr(url2, 18))
where url2 like 'http://oldurl.com%';
您也可以在一次更新中完成此操作:
update breadcrumbs
set url1 = (case when url1 like 'http://oldurl.com%'
then concat('http://newurl.com', substr(url1, 18))
else url1 end),
url2 = (case when url2 like 'http://oldurl.com%'
then concat('http://newurl.com', substr(url2, 18))
else url2 end)
where url1 like 'http://oldurl.com%' or
url2 like 'http://oldurl.com%';
一种简单的方法是使用两个更新:
update breadcrumbs
set url1 = concat('http://newurl.com', substr(url1, 18))
where url1 like 'http://oldurl.com%';
update breadcrumbs
set url2 = concat('http://newurl.com', substr(url2, 18))
where url2 like 'http://oldurl.com%';
您也可以在一次更新中完成此操作:
update breadcrumbs
set url1 = (case when url1 like 'http://oldurl.com%'
then concat('http://newurl.com', substr(url1, 18))
else url1 end),
url2 = (case when url2 like 'http://oldurl.com%'
then concat('http://newurl.com', substr(url2, 18))
else url2 end)
where url1 like 'http://oldurl.com%' or
url2 like 'http://oldurl.com%';
对每个要替换字符串的列执行此操作
请参阅MySQL手册中的
update breadcrumbs
set url1 = replace(url1, 'oldurl.com', 'newurl.com'),
url2 = replace(url2, 'oldurl.com', 'newurl.com')
where url1 like 'http://oldurl.com%'
or url2 like 'http://oldurl.com%'
对每个要替换字符串的列执行此操作
请参阅MySQL手册中的。您缺少一堆结束引号。@Barmar。非常感谢。早上好你少了一堆结束语。@Barmar。非常感谢。早上好
update breadcrumbs
set url1 = replace(url1, 'oldurl.com', 'newurl.com'),
url2 = replace(url2, 'oldurl.com', 'newurl.com')
where url1 like 'http://oldurl.com%'
or url2 like 'http://oldurl.com%'