ESCAPE appears after a LIKE or SIMILAR TO predicate and defines one character that turns the following character into a literal. Without ESCAPE, % matches any length string and _ matches a single character. By declaring an escape character, you can search for these symbols themselves (or other special tokens) inside text columns.The escape character must be a single, quoted character literal. When the database engine scans the pattern, any occurrence of the escape character causes the next character to be interpreted verbatim rather than as a wildcard. Only the specified character acts as the escape indicator; all other characters are evaluated normally.An ESCAPE clause is optional. If omitted, no escaping is available and wildcard symbols keep their special meaning. The clause is evaluated per expression, so different predicates can use different escape characters in the same query.Caveats:- The escape character cannot be a multi-byte string.- Choosing a character that also appears often in the data or pattern leads to verbose patterns and harder maintenance.- Some drivers automatically double the escape character when formatting strings; be sure to pass the exact pattern you intend.
escape_character
(char(1)) - The single character that signals the next character should be treated literallyLIKE, SIMILAR TO, ILIKE, REGEXP, PATTERN MATCHING, WILDCARD CHARACTERS
SQL-92
Use an ESCAPE clause with a chosen delimiter: `WHERE name LIKE '%!%%' ESCAPE '!'` treats `%` as a literal.
No. The SQL standard permits only a single character. Multi-character escapes raise a syntax error.
Yes. Append `ESCAPE ''` after the SIMILAR TO expression to override the default escape semantics.
The escape character itself is not case sensitive, but the pattern comparison follows the column collation unless you use case-insensitive operators.