SQL更新中的str_replace吗? [英] str_replace in SQL UPDATE?

查看:90
本文介绍了SQL更新中的str_replace吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个示例表:

name       |   picture

John S.    |   http://servera.host.com/johns.png
Linda B.   |   http://servera.host.com/lindab.png
...

比方说还有几百条记录.

Let's say there are several hundred more records.

我们也说我们将服务器从"servera"移到了"serverb".

Let's also say we moved servers from "servera" to "serverb".

是否可以通过一个查询进入该表,以便为每条记录重命名图片"列中的内容以读取正确的服务器名称?

Would it be possible to go into this table with one query to rename the content in the column "picture" for every record to read the correct server name?

推荐答案

T-SQL:

update TBL 
   set picture = Replace(picture, 'servera', 'serverb') 
 where picture like '%servera%'

Oracle:

update TBL 
   set picture = replace(picture, 'servera', 'serverb') 
 where picture like '%servera%'

MySQL:

update TBL 
   set picture = REPLACE(picture, 'servera', 'serverb') 
 where picture like '%servera%'

这篇关于SQL更新中的str_replace吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆