- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Apostrophe replacement in MySQL query?
To replace apostrophe, you can use replace(). Following is the syntax −
update yourTableName set yourColumnName=replace(yourColumnName,'\'','');
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Sentence varchar(100) ); Query OK, 0 rows affected (0.17 sec)
Insert some records in the table using insert command. Apostrophe is added for the sentence −
mysql> insert into DemoTable(Sentence) values('Chris\'s Father'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable(Sentence) values('Larry\'s Mother'); Query OK, 1 row affected (0.06 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+----------------+ | Id | Sentence | +----+----------------+ | 1 | Chris's Father | | 2 | Larry's Mother | +----+----------------+ 2 rows in set (0.00 sec)
Following is the query to replace apostrophe −
mysql> update DemoTable set Sentence=replace(Sentence,'\'',''); Query OK, 2 rows affected (0.07 sec) Rows matched: 2 Changed: 2 Warnings: 0
Let us display records from the table to check apostrophe have been replaced or not.
mysql> select *from DemoTable;
This will produce the following output −
+----+---------------+ | Id | Sentence | +----+---------------+ | 1 | Chriss Father | | 2 | Larrys Mother | +----+---------------+ 2 rows in set (0.00 sec)
Advertisements