Escape Characters
Escape Character Table
Character Sequence | Represents Character |
---|---|
\' | Single quote ' |
\" | Double quote " |
\n | Newline |
\r | Carriage return |
\t | Tab |
\\ | Backslash \ |
\% | % (rules below) |
\_ | _ (rules below) |
Rules for Using Escape Characters
- When escape characters are in identifiers (database name, table name, column name, alias)
- Regular identifiers: Directly returns an error for invalid identifiers, as identifiers must consist of numbers, letters, and underscores, and cannot start with a number.
- Backtick `` identifiers: Remain unchanged, no escaping applied.
- When escape characters are in data
- Encountering the defined escape characters will trigger escaping (see below for
%
and_
); if no matching escape character is found, the escape character\
will be ignored (and\x
remains unchanged). - For
%
and\_
, since these characters are wildcards inLIKE
, use\\%
and\\_
to represent the literal%
and\_
in pattern matching withLIKE
. If\%
or\_
is used outside the context ofLIKE
pattern matching, they will be interpreted as the strings\%
and\_
, not as%
and\_
.
- Encountering the defined escape characters will trigger escaping (see below for