String literals are sequences of characters enclosed in single quotes (') or double quotes (").
Note
If the ANSI_QUOTES mode is enabled, only single quotes ' can be used to quote strings. The following settings and query statements are provided:
obclient> SET sql_mode = 'ANSI_QUOTES';
obclient> SELECT @@sql_mode;
String literals are divided into two types:
Binary string. The unit is bytes, and the comparison is based on bytes. The character set and collation are
binary.Non-binary string. The unit is characters, and the comparison is based on characters (some character sets support multi-byte characters). It has various character sets other than
binaryand collations compatible with the character set.
Use the COLLATE clause to specify the character set and collation for string literals:
[_charset_name]'string' [COLLATE collation_name]
In a string, an escape character is a sequence that starts with a backslash \ and represents a special meaning. Escape characters are case-sensitive. For example, \b represents a backspace, but \B represents B.
The following table lists all escape characters:
| Escape character | Description |
|---|---|
\b |
Backspace character. |
\f |
Form feed character. |
\n |
Newline character. |
\r |
Carriage return character. |
\t |
Tab character. |
\\ |
Backslash character. |
\' |
Single quote character. |
\" |
Double quote character. |
\_ |
Underscore character. |
\% |
Percent character. |
\0 |
NULL character. |
\Z |
ASCII 26 control character Ctrl+Z |
