How MySQL REPLACE() function replaces strings in multiple records?

MySQLMySQLi Database

If we want to replace strings in multiple records then REPLACE() function must have the column name as 1st argument i.e. at the place of string. It means that, it will replace all the substring with another substring in that particular column. We can also use REPLACE() function with WHERE clause along with UPDATE statement to apply conditions. It is exhibit with the following example:


mysql> Update Student set Name = REPLACE(Name, 'G','S') WHERE Subject LIKE '%Comp%';
Query OK, 2 rows affected (0.08 sec)
Rows matched: 2 Changed: 2 Warnings: 0

The above query replaces strings in multiple records of Student table.

mysql> Select Name, Subject from Student;
| Name    | Subject   |
| Saurav  | Computers |
| Aarav   | History   |
| Harshit | Commerce  |
| Saurav  | Computers |
| Yashraj | Math      |
5 rows in set (0.00 sec)
Updated on 07-Feb-2020 10:43:24