tags:

views:

1391

answers:

4

How do I insert a Value in Mysql that consist of single of Double Quotes. i.e,

Value: This is Ashok's Pen.

This Single Quote will create problems.

There might be other escape characters...

How to insert the data properly..

Thanks in advance for ur precious time..

A: 

' is the escape character. So your string should be: This is Ashok''s Pen

Edit:

If you are using some front-end code, you need to do a string replace before sending the data to the SP.

For eg. in C# you can do

value = value.Replace("'","''");

and then pass value to SP.

Rashmi Pandit
I m not inserting data manually, I extract it from File, and there will be vaklues: Ashok's pen.How to insert it. creaetd a procedure for doing this..how to make it correct.
Ashok Gupta
Are you calling the SP through code?
Rashmi Pandit
+1  A: 

Put quite simply:

SELECT 'This is Ashok''s Pen.';

So inside the string, replace each single quote with two of them.

Or:

SELECT 'This is Ashok\'s Pen.'

Escape it =)

Rob
You might want to update your post to include mysql_real_escape_string() or addslashes() as possible solutions... as in one of the comments below, the OP states that they're just reading from file and inserting.
James Burgess
A: 

See my answer to "How to escape characters in MySQL"

Whatever library you are using to talk to MySQL will have an escaping function built in, e.g. in PHP you could use mysql_real_escape_string

Paul Dixon
I m not inserting data manually, I extract it from File, and there will be values: Ashok's pen. How to insert it. created a procedure for doing this.. how to make it correct.
Ashok Gupta
A: 

You should escape the special characters using the \ charactor.



This is Ashok's Pen.

becomes;

This is Ashok\'s Pen.

simon622