>>-match-expression----+-----+--LIKE--pattern-expression--------> '-NOT-' >-----+----------------------------+--------------------------->< '-ESCAPE--escape-expression--'
The LIKE predicate searches for strings that have a certain pattern. The pattern is specified by a string in which the underscore and percent sign may have special meanings. Trailing blanks in a pattern are part of the pattern.
If the value of any of the arguments is null, the result of the LIKE predicate is unknown.
The values for match-expression, pattern-expression, and escape-expression are compatible string expressions. There are slight differences in the types of string expressions supported for each of the arguments. The valid types of expressions are listed under the description of each argument.
None of the expressions can yield a distinct type. However, it can be a function that casts a distinct type to its source type.
The expression can be specified by any one of:
The expression can be specified by any one of:
with the restrictions that:
A simple description of the use of the LIKE pattern is that the pattern is used to specify the conformance criteria for values in the match-expression where:
If the pattern-expression needs to include either the underscore or the percent character, the escape-expression is used to specify a character to precede either the underscore or percent character in the pattern.
A rigorous description of the use of the LIKE pattern follows. Note that this description ignores the use of the escape-expression; its use is covered later.
The result of the predicate is unknown if m or p is the null value. Otherwise, the result is either true or false. The result is true if m and p are both empty strings or there exists a partitioning of m into substrings such that:
It follows that if p is an empty string and m is not an empty string, the result is false. Similarly, it follows that if m is an empty string and p is not an empty string, the result is false.
The predicate m NOT LIKE p is equivalent to the search condition NOT (m LIKE p).
When the escape-expression is specified, the pattern-expression must not contain the escape character identified by the escape-expression except when immediately followed by the escape character, the underscore character or the percent sign character (SQLSTATE 22025).
If the match-expression is a character string in an MBCS database then it can contain mixed data. In this case, the pattern can include both SBCS and MBCS characters. The special characters in the pattern are interpreted as follows:
The expression can be specified by any one of:
with the restrictions that:
When escape characters are present in the pattern string, an underscore, percent sign, or escape character can represent a literal occurrence of itself. This is true if the character in question is preceded by an odd number of successive escape characters. It is not true otherwise.
In a pattern, a sequence of successive escape characters is treated as follows:
Following is a illustration of the effect of successive occurrences of the escape character (which, in this case, is the back slash (\) ).
The code page used in the comparison is based on the code page of the match-expression value.
SELECT PROJNAME FROM PROJECT WHERE PROJECT.PROJNAME LIKE '%SYSTEMS%'
SELECT FIRSTNME FROM EMPLOYEE WHERE EMPLOYEE.FIRSTNME LIKE 'J_'
SELECT FIRSTNME FROM EMPLOYEE WHERE EMPLOYEE.FIRSTNME LIKE 'J%'
SELECT LA_SERVERS FROM CORP_SERVERS WHERE CORP_SERVERS.LA_SERVERS LIKE CURRENT SERVER
SELECT A FROM T WHERE T.A LIKE '\%\_\\%' ESCAPE '\'
SELECT COLBLOB FROM TABLET WHERE COLBLOB LIKE :pattern_var ESCAPE BLOB(X'OE')