A string literal is a sequence of characters enclosed in single quotes ' or double quotes ".
Note
If you enable ANSI_QUOTES mode, only single quotes ' can be used to enclose strings. The syntax for setting and querying this mode is as follows:
obclient> SET sql_mode = 'ANSI_QUOTES';
obclient> SELECT @@sql_mode;
String literals are classified into the following two types:
A binary string. The unit is bytes, and bytes are used for comparison. The character set and collation are
binary.Non-binary strings. The unit is a character, and character comparison is used (some character sets support multibyte characters). It supports multiple character sets other than
binaryand collations compatible with those character sets.
You can use the following COLLATE clause to specify the character set and collation for string literals:
[_charset_name]'string' [COLLATE collation_name]
In strings, escape characters are formed by preceding certain sequences with a backslash \. They are used to represent special meanings. Escape characters are case-sensitive. For example, \b represents a backspace, but \B represents the letter B.
The following table lists all escape characters:
Escape character |
Meaning |
|---|---|
\b |
Backspace |
\f |
Page Break |
\n |
Line Break |
\r |
Carriage Return |
\t |
Tab Character |
\\ |
Backslash character |
\' |
Single Quotation Mark |
\" |
double quotation mark |
\_ |
underline |
\% |
percent sign |
\0 |
NULL |
\Z |
ASCII 26 control character Ctrl+Z |