Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2023-09-01 16:57:09
forward
958 people have browsed it

如何将 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!