我们知道 REPLACE() 函数用于将字符串中出现的一个子字符串替换为另一个子字符串。我们还可以使用 REPLACE 函数和 UPDATE 语句来更新表。以下示例将演示它 -
示例
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)
上面的查询通过查找“Mr.”并将其替换为“Shri”来更新列 Father_name。