Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Update and replace substring [duplicate]

Tags:

sql

mysql

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

like image 345
Aryan Avatar asked May 02 '13 09:05

Aryan


People also ask

How do you replace a substring in a string in SQL?

SQL Server REPLACE() Function The REPLACE() function replaces all occurrences of a substring within a string, with a new substring. Note: The search is case-insensitive.

How do I replace multiple characters in a string in SQL?

SELECT REPLACE(REPLACE(REPLACE(REPLACE('3*[4+5]/{6-8}', '[', '('), ']', ')'), '{', '('), '}', ')'); We can see that the REPLACE function is nested and it is called multiple times to replace the corresponding string as per the defined positional values within the SQL REPLACE function.


1 Answers

use REPLACE()

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

but remember that REPLACE() is case sensitive.

like image 88
John Woo Avatar answered Oct 14 '22 06:10

John Woo