Home  >  Article  >  Database  >  How to use REPLACE() with the UPDATE clause to make permanent changes to a table?

How to use REPLACE() with the UPDATE clause to make permanent changes to a table?

WBOY
WBOYforward
2023-09-01 16:57:09959browse

如何将 REPLACE() 与 UPDATE 子句一起使用来对表进行永久更改?

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 -

Example

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete