We know that the REPLACE() function is used to replace one substring appearing in a string with another substring. We can also update the table using REPLACE function and UPDATE statement. The following example will demonstrate it -
mysql> Update Student set Father_Name = REPLACE(Father_Name, 'Mr.','Shri '); Query OK, 5 rows affected (0.06 sec) Rows matched: 5 Changed: 5 Warnings: 0 mysql> Select Name, Father_Name from Student; +---------+-----------------+ | Name | Father_Name | +---------+-----------------+ | Gaurav | Shri Ramesh | | Aarav | Shri Sanjay | | Harshit | Shri Lovkesh | | Gaurav | Shri Ramchander | | Yashraj | Shri Mohan | +---------+-----------------+ 5 rows in set (0.00 sec)
The above query updates the column Father_name by finding "Mr." and replacing it with "Shri".
The above is the detailed content of How to use REPLACE() with the UPDATE clause to make permanent changes to a table?. For more information, please follow other related articles on the PHP Chinese website!