SQL Update并替换substring [duplicate]

时间:2021-01-07 19:16:52

This question already has an answer here:

这个问题在这里已有答案:

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中进行查询,将name中的所有'a'更改为name表中first_name列中的'b'。这是我的列名:first_name |列表名称

2 个解决方案

#1


40  

use REPLACE()

使用REPLACE()

UPDATE tableName
SET first_name = REPLACE(first_name, 'a', 'b')

but remember that REPLACE() is case sensitive.

但请记住,REPLACE()区分大小写。

#2


4  

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

#1


40  

use REPLACE()

使用REPLACE()

UPDATE tableName
SET first_name = REPLACE(first_name, 'a', 'b')

but remember that REPLACE() is case sensitive.

但请记住,REPLACE()区分大小写。

#2


4  

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