LIKE Predicate
- Last Updated: December 12, 2014
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
The LIKE predicate searches
for strings that have a certain pattern. The pattern is specified
after the LIKE keyword in a string constant. The
pattern can be specified by a string in which the underscore ( _
) and percent sign ( % ) characters have special semantics.
Use
the ESCAPE clause to disable the special semantics
given to the characters ( _ ) and
( % ). The escape character specified must precede the special characters in order to disable their special semantics.
Syntax
This
is the syntax for a LIKE predicate:
|
Notes
- The column_name specified
in the
LIKEpredicate can be a column, a string constant, or an arbitrary character expression (such asSUBSTRINGorLTRIM). - The string_constant may be a string constant or a scalar function call.
- The escape_character must be a one character string constant.
- A percent sign ( % ) in the pattern matches zero or more characters of the column string.
- An underscore symbol ( _ ) in the pattern matches any single character of the column string.
- The
LIKEpredicate is multi‑byte enabled. The string_constant and the escape_character may contain multi‑byte characters, and the escape_character can be a multi‑byte character. A percent sign ( % ) or an underscore ( _ ) in the string_constant can represent a multi‑byte character. However, the percent sign or underscore itself must be the single‑byte ASCII encoding.
Example
This
example illustrates three ways to use the LIKE predicate:
|
In the first LIKE clause, for
all strings with the substring 'Computer' the predicate evaluates
to true. In the second LIKE clause, for all strings
which are exactly three characters long the predicate evaluates
to true. In the third LIKE clause the backslash
character ( \ ) is specified as the escape character, which means
that the special interpretation given to the underscore character
( _ ) is disabled. The pattern evaluates to TRUE if
the item_name column has embedded underscore characters.