Using SELECT REPLACE with MySQL

by Rekha 2010-01-28 14:12:02

You can find and replace text in mysql using REPLACE function.

The REPLACE() function takes three parameters:

1. the string or column name to do the replacement on
2. what to look for
3. and what to replace it with


The following example replaces the 'aaa' part of 'aaa bbb ccc' with 'xyz' and the column returned from the SQL query will contain 'xyz bbb ccc':

SELECT REPLACE('aaa bbb ccc', 'aaa', 'xyz');


If you were doing this against the column "foo" you would do this instead:

SELECT REPLACE(foo, 'aaa', 'xyz');

Tagged in:

1201
like
0
dislike
0
mail
flag

You must LOGIN to add comments