
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Remove All Instances of a Specific Character from a Column in MySQL
Let us first create a table −
mysql> create table DemoTable -> ( -> FirstName varchar(100) -> ); Query OK, 0 rows affected (0.41 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Adam^^^'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('^^^^^^^^Carol'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Robert^^^^^^'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+---------------+ | FirstName | +---------------+ | Adam^^^ | | ^^^^^^^^Carol | | Robert^^^^^^ | +---------------+ 3 rows in set (0.00 sec)
Following is the query to remove all instances of a specific character from a column in MySQL. Here, we are removing all the instances of the special character ^ −
mysql> update DemoTable set FirstName=replace(FirstName,'^',''); Query OK, 3 rows affected (0.20 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check table records once again −
mysql> select *from DemoTable;
Output
This will produce the following output −
+-----------+ | FirstName | +-----------+ | Adam | | Carol | | Robert | +-----------+ 3 rows in set (0.00 sec)
Advertisements