Reputation: 21
Dear friends on Stackoverflow,
I recently started learning SQL and I'm currently trying to add ' as a value into MYSQL Community edition.
For example, In order to add the letter A id' put
INSERT INTO symbols (test_chars) VALUES ('A');
But If I wanted to add the ' itself how would go about doing that?
''' Is not working for me and I have a feeling that's not how it should work.
Much appreciated and Best Regards,
Waqar
Upvotes: 1
Views: 53
Reputation: 72186
The documentation is your best friend.
There are several ways to include quote characters within a string:
- A
'
inside a string quoted with'
may be written as''
.- A
"
inside a string quoted with"
may be written as""
.- Precede the quote character by an escape character (
\
).- A
'
inside a string quoted with"
needs no special treatment and need not be doubled or escaped. In the same way,"
inside a string quoted with'
needs no special treatment.
As you can see there are three possible solutions to your problem. Pick your favorite.
Upvotes: 0
Reputation: 1269593
You use a lot of single quotes. Doubling a single quote in a string is a single quote. So, four single quotes in a row defines a string with one single quote:
INSERT INTO symbols (test_chars) VALUES ('''');
The quotes at the beginning and end delimit the string. The two quotes in the middle are the single quote character.
This is ANSI standard and should work in any database.
Upvotes: 3