Show TOC

Like predicateLocate this document in the navigation structure

The like predicate is used to test if a value matches a pattern.

Syntax

<like predicate> ::= 
             <match value> ( NOT )? LIKE <pattern value> 
             ( ESCAPE <escape character> )?.

<match value> ::= <column reference>.

<pattern value> ::= 
                            <string literal> 
                            | <dynamic parameter specification>.

<escape character> ::= 
                                  <string literal> 
                                  | <dynamic parameter specification>.

            

The data types of the <match value> , <pattern value> and <escape character> must be character types and comparable to each other.

If an <escape character> is specified the length of its value must be one character.

The <like predicate> "match NOT LIKE pattern ESCAPE escape" is equivalent to the <boolean factor> "NOT ( match LIKE pattern ESCAPE escape )".

The <like predicate> "match NOT LIKE pattern" is equivalent to the <boolean factor> "NOT ( match LIKE pattern )".

If either the <match value> or the <pattern value> is the NULL value, the result of the <like predicate> is unknown.

If an <escape character> is specified and the <escape character> is the NULL value, the result of the <like predicate> is unknown.

The result of the <like predicate> is true, if the <match value> matches the <pattern value> , otherwise the result of the <like predicate> is false.

Matching is done by comparing character wise the <match value> with the <pattern value> where the underscore character '_' stands for exactly one arbitrary character and the percent character '%' stands for an arbitrary string (sequence of arbitrary length (including zero length) of arbitrary characters).

If an <escape character> is specified, the <escape character> can be used to escape the special meaning of the underscore and the percent character. Shall E be the <escape character> . Then the character sequence "E_" in the <pattern value> matches the occurrence of one underscore character "_" in the <match value> , the sequence "E%" in the <pattern value> matches the occurrence of one percent character "%" in the <match value> and the sequence "EE" in the <pattern value> matches the occurrence of one "E" in the <match value> , all other sequences that start with "E" are invalid.

Example

SELECT * FROM a WHERE c LIKE 'x%'
            

LIKE . This SELECT yields all rows from table a where the value of the column a.c starts with the character 'x'.