
- 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 REPLACE() be used with UPDATE clause to make permanent changes to a 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 the REPLACE function with the UPDATE statement to update the table. 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 has updated the column Father_name by finding ‘Mr.’ and replacing the same with ‘Shri’.
- Related Articles
- How can MySQL REPLACE() function be used with WHERE clause?
- How can MySQL find and replace the data with REPLACE() function to UPDATE the table?
- How can CONCAT() function be used with MySQL WHERE clause?
- How can CONCAT_WS() function be used with MySQL WHERE clause?
- How LOCATE() function can be used with MySQL WHERE clause?
- How MySQL LTRIM() and RTRIM()functions can be used with WHERE clause?
- How BEFORE UPDATE triggers can be used to emulate CHECK CONSTRAINT\nfor updating values in the table?
- How can Tensorflow be used with Estimator to make predictions from trained model?
- How can group functions be used in ORDER BY clause?
- How Groups function can be used in MySQL SELECT clause?
- Can The Soil From A Field Can Be Used To Make Toys ?
- Can a number be used to name a MySQL table column?
- What are irreversible changes? Are they permanent changes and cannot be reversed?
- How to replace rows in a MySQL table with conditions?
- How to update DB2 table with a duplicate primary key?

Advertisements