Here's a sample table:

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.

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%'

Mysql相关问答推荐

在mySQL中使用子查询和WHERE子句的JOIN

SQL中的搜索模式

mysql使用LIKE查找二进制字段有问题

递归查询意外地为一个字段返回空值

为什么 MAX 函数通过调用在 group 中生成正确的结果

计算同一个表中的两列,然后将两者都算作总数

为大表优化 Django 模型

在 MySQL 中,如何对 LIKE 查询进行批量更新,删除字符?

如何找到每个user_id每个产品的买家类型数量?

检索按键列值分组的最新日期 (MySql)

谁能帮我优化where子句

查询mysql中无法识别数据值

MySQL IF() 函数根据指定条件执行代码块

MySQL 查询组按日期(12 小时间隔)

MySQL查询根据同一表中其他字段的值更新表中的字段

如何在 MySQL 中 Select 字段具有最小值的数据?

MySQL - 如何在 INSERT 语句中将字符串值解析为 DATETIME 格式?

如何在sequelize中定义多列的唯一索引

你如何 OR 两个 LIKE 语句?

将行插入 MySQL 数据库的最有效方法