MySQL escape characters

Source: Internet
Author: User
For more information, see MySQL escape characters.

For more information, see MySQL escape characters.

MySQL Escape Character "\"
Mfc_basic
MySQL recognizes the following escape characters:
\ 0
An ASCII 0 (NUL) character.
\ N
A newline character.
\ T
A positioning character. Separator
\ R
A carriage return.
\ B
A return character.
\'
A single quotation mark.
\"
A double quotation mark.
A backslash.
\ %
A "%" character. It is used to search for the text instance of "%" in the body. Otherwise, "%" is interpreted as a wildcard.
\_
A "_" character. It is used to search for the text instance of "_" in the body. Otherwise, "_" is interpreted as a wildcard.
Note: If you use "\ %" or "\ % _" in some body environments _", these will return strings "\ %" and "\ _" instead of "%" and "_".
★★
There are several methods to enclose quotation marks in a string:
1. Escape:
A string is referenced by a single quotation mark ('). The single quotation mark (') character in the string can be escaped by a single quotation mark.
A string is referenced by double quotation marks (""). The character "" In this string can be escaped.
At the same time, you can continue to use an escape character "\" to escape
2. Escape-free:
A string is referenced by double quotation marks (""). The single quotation marks (') in the string do not need to be treated specially and do not need to be repeated or escaped.
Likewise,
A string is referenced by single quotation marks ('). The double quotation marks ("") in the string do not need to be treated specially and do not need to be repeated or escaped.
The following SELECT statement demonstrates how quotes and escaping work:
Mysql> SELECT 'hello', '"hello"', '"hello" "', 'Hello', '\ 'hello ';
+ ------- + --------- + ----------- + -------- +
Please hello everyone "hello" everyone "" hello "" chela'lo then 'Hello everyone
+ ------- + --------- + ----------- + -------- +
Mysql> SELECT "hello", "'hello'", "'hello'", "El" "lo", "\" hello ";
+ ------- + --------- + ----------- + -------- +
When hello, then 'hello' then 'hel "lo done" hello
+ ------- + --------- + ----------- + -------- +
Mysql> SELECT "This \ nIs \ nFour \ nlines ";
+ -------------------- +
Else This
Is
Four
Lines
+ -------------------- +
★★
If you want to insert binary data into a BLOB column, the following characters must be represented by escape sequences:
NUL
ASCII 0. You should use '\ 0' (a backslash and an ASCII '0') to represent it.
ASCII 92, backslash. .
'
ASCII 39, single quotes. It is represented.
"
ASCII 34, double quotation marks. It is represented.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.