
- 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 to replace a particular character in a MySQL column?
To replace a particular character, use REPLACE() and to update, use the UPDATE command. Let us first create a table −
mysql> create table DemoTable1899 ( Code varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1899 values('John_123'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1899 values('32189_Sam_987'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1899 values('Miller_David_456_909'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1899;
This will produce the following output −
+----------------------+ | Code | +----------------------+ | John_123 | | 32189_Sam_987 | | Miller_David_456_909 | +----------------------+ 3 rows in set (0.00 sec)
Here is the query to replace a particular character −
mysql> update DemoTable1899 set Code=replace(Code,'_',''); Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again:
mysql> select * from DemoTable1899;
This will produce the following output −
+-------------------+ | Code | +-------------------+ | John123 | | 32189Sam987 | | MillerDavid456909 | +-------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to replace a character in a MySQL table?
- How do I replace a character at a particular index in JavaScript?
- In MySQL how to replace all NULL values in a particular field of a particular table?
- MySQL query to replace a column value
- How to find and replace string in MySQL database for a particular string only?
- How to remove a particular character from a String.
- In MySQL, how can we get the number code of a particular character?
- Replace only a specific value from a column in MySQL
- How can I check the character set of all the tables along with column names in a particular MySQL database?
- How to get a value more than a particular value from varchar column in MySQL?
- How to find string count of a particular id in a column using a MySQL query?
- How to remove all instances of a specific character from a column in MySQL?
- How to divide each column by a particular column in R?
- Update a column of text with MySQL REPLACE()
- How to update all the entries except a single value in a particular column using MySQL?

Advertisements