Muokkaa

Jaa


LIKE Predicate Escape Character

In a LIKE predicate, the percent sign (%) matches zero or more of any character and the underscore (_) matches any one character. To match an actual percent sign or underscore in a LIKE predicate, an escape character must come before the percent sign or underscore. The escape sequence that defines the LIKE predicate escape character is:

{escape ' escape-character '}

where escape-character is any character supported by the data source.

For more information about the LIKE escape sequence, see LIKE Escape Sequence in Appendix C: SQL Grammar.

For example, the following SQL statements create the same result set of customer names that start with the characters "%AAA". The first statement uses the escape-sequence syntax. The second statement uses the native syntax for Microsoft Access and is not interoperable. Notice that the second percent character in each LIKE predicate is a wildcard character that matches zero or more of any character.

SELECT Name FROM Customers WHERE Name LIKE '\%AAA%' {escape '\'}  
  
SELECT Name FROM Customers WHERE Name LIKE '[%]AAA%'  

To determine whether the LIKE predicate escape character is supported by a data source, an application calls SQLGetInfo with the SQL_LIKE_ESCAPE_CLAUSE option.