MySQL SQL 更新和替换子字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16334813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:31:26 来源:igfitidea点击:
SQL Update and replace substring
提问by Aryan
I want a query in SQL that change all 'a' in string to 'b' in first_name column in name table. Here is my columns name: first_name | list_name
我想要一个 SQL 查询,将字符串中的所有 'a' 更改为名称表中 first_name 列中的 'b'。这是我的列名:first_name | 列表名称
回答by John Woo
use REPLACE()
用 REPLACE()
UPDATE tableName
SET first_name = REPLACE(first_name, 'a', 'b')
but remember that REPLACE()is case sensitive.
但请记住,这REPLACE()是区分大小写的。
回答by Aryan
You can try this:
你可以试试这个:
UPDATE name SET first_name = REPLACE (first_name, 'a', 'b') WHERE blabla LIKE '%blabla%';
OR
UPDATE name SET first_name = REPLACE (first_name, 'a', 'b') WHERE blabla = 'blabla';

