MySQL Escape Character Usage Instructions _mysql

Source: Internet
Author: User
MySQL escape character "\"
Mfc_basic
MySQL recognizes the following escape characters:
The
An ASCII 0 (NUL) character.
\ n
A new line character.
\ t
A locator character. System character separation
\ r
A carriage return character.
\b
A backspace.
\'
A single quotation mark ("'") character.
\"
A double quotation mark ("") character.
A backslash ("\") character.
\%
A "%" character. It is used to search for text instances of "%" in the body, otherwise this "%" will be interpreted as a wildcard character.
\_
An "_" character. It is used to search for text instances of "_" in the body, otherwise this "_" will be interpreted as a wildcard character.
Note that if you use "\%" or "\%_" in some body contexts, these will return the string "\%" and "\_" instead of "%" and "_".

There are several ways to include quotes within a string:
1, must be escaped:
A string is referenced in single quotation marks "'", and the single quote "'" character in the string can be escaped with "".
A string is referenced in double quotation marks "", and the character "" in the string can be escaped by using the "" ".
You can also continue to use an escape character "\" to escape
2, not escaped:
A string is quoted in double quotes "" "and the single quotation mark in the string" ' "does not require special treatment and does not have to be duplicated or escaped.
Similarly
A string is referred to as a single quote "'" and the double quotation mark "" In the string does not require special treatment and does not have to be duplicated or escaped.
The select shown below demonstrates how quotes and escapes work:
mysql> SELECT ' hello ', ' hello ' ', ' ' Hello ' ', ', ' Hel ' ' lo ', ' hello ';
+-------+---------+-----------+--------+--------+
¦hello¦ "Hello" ¦ "Hello" "¦hel ' lo¦ ' hello¦
+-------+---------+-----------+--------+--------+
mysql> SELECT "Hello", "Hello", "' Hello '" "," Hel "" Lo "," Hello ";
+-------+---------+-----------+--------+--------+
¦hello¦ ' hello ' ¦ ' hello ' ¦hel ' lo¦ ' hello¦
+-------+---------+-----------+--------+--------+
mysql> select "This\nis\nfour\nlines";
+--------------------+
¦this
Is
Four
lines¦
+--------------------+

If you want to insert binary data into a BLOB column, the following characters must be represented by an escape sequence:
NUL
ASCII 0. You should use ' the ' (a backslash and an ASCII ' 0 ') to represent it.
ASCII 92, backslash. By ' \ \ '.
'
ASCII 39, single quotes. Use "\" to indicate.
"
ASCII 34, double quotes. "\" is used to indicate the.
Related Article

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.