The single quote and apostrophe (s) are commonly used with any kind of text data.
To escape or ignore the single quote is a common requirement for all database developers.
In this post, I am sharing solution for MySQL Database Server.
MySQL Server has actually two options to escape single quote. You can replace single quote to double single quote like (”) and the other is you can use (\’) to escape single quote.
First, Create a sample table:
1
2
3
4
5
|
CREATE TABLE tbl_SingleQuoted
(
ID INTEGER
,TextData TEXT
);
|
Insert some sample data with single quote using both (”) and (\’):
1
2
3
4
5
|
INSERT INTO tbl_SingleQuoted
VALUES
(1,'Anvesh\'s dbrnd.com')
,(2,'Database\'s Properties')
,(3,'The dbrnd Blog''s Reviews');
|
To SELECT all data which has ( ‘s ):
1
2
3
|
SELECT *
FROM tbl_SingleQuoted
WHERE TextData LIKE '%\'s%';
|
The Result:
0 comments:
Post a Comment