MySQL supports replace() function which returns the string input_str with all occurrences of the string from_string replaced by the string to_string. REPLACE() performs a case-sensitive match when searching for from_string.
REPLACE(input_str,from_string,to_string)
For example:
[text] mysql> SELECT REPLACE(‘http://www.4rapiddev.com’, ‘http://www.’, ‘http://’);-> http://4rapiddev.com
[/text]
You also can use the Replace() function to find and replace an original string with another string in a column (field) of a particular database table.
[text] update table_name set column_name = replace(column_name, ‘old_string’, ‘new_string’);[/text]
It updates new data for the specified column_name in which all occurrences of a specified string in the current instance are replaced with another specified string.
Whereas:
- table_name: the table contains the column field
- column_name: specify which column field you want to do replace
- old_string: the string to be replaced
- new_string: the string to replace all occurrences of old_string