
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can MySQL find and replace the data with REPLACE() function to UPDATE the table?
As we know that REPLACE () function is used to replace the occurrences of a substring with another substring within a string. We can also use REPLACE function with UPDATE statement to update the table by finding and replacing the data.
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 has updated the column Father_name by finding ‘Mr.’ and replacing the same with ‘Shri’.
- Related Articles
- How to use REPLACE() function with column’s data of MySQL table?
- How can MySQL REPLACE() function be used with WHERE clause?
- How can REPLACE() be used with UPDATE clause to make permanent changes to a table?
- Update a column of text with MySQL REPLACE()
- Find and Replace text in the entire table using a MySQL?
- How to replace rows in a MySQL table with conditions?
- MySQL: How can I find a value with special character and replace with NULL?
- How can I use MySQL replace() to replace strings in multiple records?
- How can I find and replace in MySQL in a column with file path?
- How to replace a character in a MySQL table?
- MySQL query to replace only the NULL values from the table?
- MySQL replace values in a table?
- Replace the empty values from a MySQL table with a specific value
- How can we use MySQL REPLACE statement to prevent of insertion of duplicate data?
- How can I replace & with an ampersand in my MySQL database?

Advertisements