MySQL data storage special character processing details
- 2020-06-01 11:12:15
- OfStack
In a string, if a sequence has a special meaning, each sequence begins with a backslash (" "), known as an escape character. MySQL recognizes the following escape characters:
0
1 ASCII 0 (NUL) character.
'
1 single quotation mark (" '") character of ASCII 39.
"
1 ASCII 34 double quotation mark (" ") character.
1 ASCII 8 backspace character.
1 ASCII 10 newline character.
r
1 ASCII 13 carriage return.
t
1 ASCII 9 TAB character (TAB).
z
ASCII (Control - Z) (26). This character handles the problem of ASCII(26) representing the end of a file in the Windows system. (when using mysql database
<
When filename, ASCII(26) may cause problems.
1 ASCII 92 backslash (" ") character.
%
1 ASCII 37 "%" character. It is used to search the body for literal instances of "%", which would otherwise be interpreted as a wildcard.
_
1 ASCII 95 "_" character. It is used to search the body for literal instances of "_", which would otherwise be interpreted as a wildcard.
Note that if the environment in some text using "%" or "_", returns the string "%" and "_" instead of "%" and "_".
A string containing quotation marks can be written in the following ways:
A string is referenced with a single quote "'". The single quote "'" character in the string can be escaped with a single quote "'".
A string is quoted with the double quotation mark "". The "" character in the string can be escaped with "" "".
You can also continue to use the escape character "" before the quotation marks.
A string is referenced with the double quotation mark "". The single quotation mark" '" in the string does not require special treatment and does not need to be repeated or escaped. Similarly, when a string is referenced with a single quote "'", the double quote "" in that string does not require special treatment and does not need to be repeated or escaped.
The SELECT demo shown below shows how quotation marks and escapes work:
mysql > SELECT 'hello', '"hello"', '""hello""', 'hel''lo', ''hello