Previous Topic: Using LIKE Predicates in WHERE ClausesNext Topic: Using the ESCAPE Keyword


Comparing Character Strings

A LIKE predicate compares a column to a wildcard value you specify and selects columns conforming to the wildcard value. Use this syntax for a LIKE predicate:

WHERE colname LIKE 'wildcard'

You must enclose the wildcard value in single quotes. A wildcard can include any combination of characters and either the percent sign (%) or the underscore (_).

The percent sign denotes any set of characters, including blanks. For example, the following clause shown selects from the NAME column all of the following values: CIC, ACICX, ABCIC, CICXYZ.

WHERE NAME LIKE '%CIC%'

The underscore denotes only one character in a specific position. For each character of column data you do not want to match, the wildcard must include an underscore. For instance, to find the NAME column in the SYSTEMS table that contains exactly three characters with M as the middle character, use the following LIKE predicate:

WHERE NAME LIKE '_M_'

The predicate shown above finds the value IMS, the only value in SYSTEMS matching the wildcard. This predicate does not find other columns with M as their second data character, such as a column containing the text OMEGAMON. To find that row, you would use the following LIKE predicate:

WHERE NAME LIKE '_M______'