在MySQL中替换 [英] Replace in MySQL

查看:119
本文介绍了在MySQL中替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,我有一些类似的记录,共有2列:

In my database I have a few records like these with 2 columns:

 Id, Name,

11,  Meal 997,
12,  Meal 998,
13,  Meal 999,
14,  Meam 000,
15,  Meam 001,
16,  Meam 002,

但这是应​​用程序中的一个问题,由于逻辑错误,数据错误. 如何将包含 Meam 的记录更改为 Meal ,并继续增加记录?

But this was an issue in the application with the wrong data due to a logical error. How can we change the records containing Meam to Meal and also continue incrementing?

以上记录应如下:

11,  Meal 997,
12,  Meal 998,
13,  Meal 999,
14,  Meal 1000,
15,  Meal 1001,
16,  Meal 1002,

我们如何更改数据库?

"Meam 001"将在一个列中

"Meam 001" will be in one columm

查询内容是什么?

推荐答案

update tablename
set name=replace(name,'Meam','Meal 1')
where name like "Meam%"

您可以使用以下方法进行测试:

you can test it with:

select name, replace(name,'Meam','Meal 1')
from tablename

;)

这篇关于在MySQL中替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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