 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements
 