LIKE predicate escape clause

In an SQL LIKE predicate, the percent metacharacter (%) matches a string of zero or more characters, and the underscore metacharacter (_) matches any single character. With the predicate escape clause, you can define patterns that contain the actual percent and underscore characters.

To specify that you want these characters to represent literal values, you precede them with an escape character. You define the LIKE predicate escape character with the following syntax in a vendor escape clause:
Read syntax diagramSkip visual syntax diagramescapeescape-character
escape-character
Specifies any character that is supported by the Db2 rules and that governs the use of the ESCAPE clause.
Example: You can use either of the following forms of the escape clause to include metacharacters as literals in the LIKE predicate. In this example, both statements search for a string that ends with the percent character .
  • Short-form syntax:
    SELECT * FROM EMPLOYEE
    WHERE COMMISSION LIKE {escape '!'} '%!%'
  • Long-form syntax:
    SELECT * FROM EMPLOYEE
    WHERE COMMISSION LIKE --(*vendor(Microsoft),product(ODBC) escape '!'*)-- '%!%'

To determine if a particular data source supports LIKE predicate escape characters, call SQLGetInfo() with the InfoType argument set to SQL_LIKE_ESCAPE_CLAUSE.