String literals
A string literal is a sequence of characters enclosed in single quotes ' or double quotes ".
If ANSI_QUOTES is enabled, only single quotes ' can be used to enclose string literals. The following statements set and query this mode:
SET sql_mode = 'ANSI_QUOTES';
SELECT @@sql_mode;
String literals can be binary or non-binary:
-
Binary string literals. These are measured in bytes and compared byte by byte. The character set and collation are
binary. -
Non-binary string literals. These are measured in characters and compared character by character. They support a variety of character sets and collations other than
binary.
Use the COLLATE clause to specify the character set and collation for a string literal:
[_charset_name]'string' [COLLATE collation_name]
In a string, an escape character is a sequence of characters that starts with a backslash \ and has a special meaning. Escape characters are case-sensitive. For example, \b represents a backspace, while \B represents the character B.
The following table lists all escape characters:
| Escape character | Meaning |
|---|---|
\b | Backspace |
\f | Form feed |
\n | Newline |
\r | Carriage return |
\t | Tab |
\\ | Backslash |
\' | Single quote |
\" | Double quote |
\_ | Underscore |
\% | Percent sign |
\0 | NULL |
\Z | ASCII 26 control character Ctrl+Z |