
- 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
Update a column of text with MySQL REPLACE()
Let us first create a table −
mysql> create table DemoTable ( Code varchar(100) ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('8565-9848-7474'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('9994-6464-8737'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('6574-9090-7643'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------------+ | Code | +----------------+ | 8565-9848-7474 | | 9994-6464-8737 | | 6574-9090-7643 | +----------------+ 3 rows in set (0.00 sec)
Following is the query to replace column value −
mysql> update DemoTable set Code=replace(Code,'9994-6464-8737','9994-9999-88888'); Query OK, 1 row affected (0.10 sec) Rows matched : 3 Changed : 1 Warnings : 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+-----------------+ | Code | +-----------------+ | 8565-9848-7474 | | 9994-9999-88888 | | 6574-9090-7643 | +-----------------+ 3 rows in set (0.00 sec)
- Related Articles
- Update a MySQL column with JSON format?
- MySQL update a column with an int based on order?
- How to update MySQL column with random value?
- How can MySQL find and replace the data with REPLACE() function to UPDATE the table?
- Update a column based on another MySQL table’s column
- MySQL UPDATE column names and set None values with N/A?
- MySQL query to replace a column value
- Update a column A if null, else update column B, else if both columns are not null do nothing with MySQL
- How to update records in a column with random numbers in MySQL?
- How to update a MySQL column by subtracting a value with some conditions?
- How to update a MySQL date type column?
- Update only a single column value in MySQL
- Replace part of string in MySQL table column?
- Update a column value, replacing part of a string in MySQL?
- MySQL UPDATE the corresponding column with random number between 1-3?

Advertisements