4. Understanding the Elements of SQL Statements : Predicates in SQL : Pattern-matching Predicates : BEGINNING, CONTAINING, and ENDING Predicates
 
Share this page                  
BEGINNING, CONTAINING, and ENDING Predicates
Use BEGINNING, CONTAINING, or ENDING in a WHERE clause to search for a specified pattern in a column.
These predicates have the following syntax:
expression [NOT] BEGINNING | CONTAINING | ENDING pattern
           
[WITH CASE | WITHOUT CASE] [ESCAPE escape_character]
where
expression
Is a column name or an expression containing string functions.
BEGINNING
Matches if the pattern string is found at the beginning of the text.
CONTAINING
Matches if the pattern string is found within the text.
ENDING
Matches if the pattern string is found at the end of the text.
pattern
Specifies the pattern to be matched. The pattern must be a string literal.
The only pattern operator for these predicates is:
\|
Denotes the alternation operator, which can be used to specify alternate patterns to match.
These three predicates are essentially shorthand ways of specifying 'pattern%', '%pattern%' and '%pattern', respectively.
CONTAINING Example
To search for multiple patterns, use the alternation operator. For example, the following will match if string_1 contains ABC, 123 or xyz:
string_1 CONTAINING 'ABC@|123@|xyz' ESCAPE '@'