Sometimes i need to find and replace some strings in a column in MySQL so for this task MySQL uses the replace() function.
This is a string function and the base syntax is as follows.
select REPLACE('string/column',old_string,new_string);
mysql select REPLACE('adrian.oprea','oprea','dba');
+---------------------------------------+
| REPLACE('adrian.oprea','oprea','dba') |
+---------------------------------------+
| adrian.dba |
+---------------------------------------+
1 row in set (0,00 sec)
mysql SELECT REPLACE(user, 'r', 'i am r') from user where user='root';
+------------------------------+
| REPLACE(user, 'r', 'i am r') |
+------------------------------+
| i am root |
+------------------------------+
6 rows in set (0,00 sec)
mysql SELECT REPLACE('abc abc', 'A', 'B');
+------------------------------+
| REPLACE('abc abc', 'A', 'B') |
+------------------------------+
| abc abc |
+------------------------------+
1 row in set (0,00 sec)