background image

LIKE Expressions

<< BETWEEN Expressions | Collection Member Expressions >>
<< BETWEEN Expressions | Collection Member Expressions >>

LIKE Expressions

The path expression must have a string or numeric value. If the path expression has a NULL
value, then the value of the IN expression is unknown.
In the following example, if the country is UK the expression is TRUE. If the country is Peru it is
FALSE
.
o.country IN (
'UK', 'US', 'France')
You may also use input parameters:
o.country IN (
'UK', 'US', 'France', :country)
LIKE
Expressions
A LIKE expression determines whether a wildcard pattern matches a string.
The path expression must have a string or numeric value. If this value is NULL, then the value of
the LIKE expression is unknown. The pattern value is a string literal that can contain wildcard
characters. The underscore (_) wildcard character represents any single character. The percent
(%) wildcard character represents zero or more characters. The ESCAPE clause specifies an escape
character for the wildcard characters in the pattern value.
Table 27­3
shows some sample LIKE
expressions.
TABLE 27­3
LIKE
Expression Examples
Expression
TRUE
FALSE
address.phone LIKE
'12%3'
'123'
'12993'
'1234'
asentence.word LIKE
'l_se'
'lose'
'loose'
aword.underscored LIKE
'\_%' ESCAPE '\'
'_foo'
'bar'
address.phone NOT LIKE
'12%3'
'1234'
'123'
'12993'
NULL
Comparison Expressions
A NULL comparison expression tests whether a single-valued path expression or an input
parameter has a NULL value. Usually, the NULL comparison expression is used to test whether or
not a single-valued relationship has been set.
SELECT t
FROM Team t
WHERE t.league IS NULL
This query selects all teams where the league relationship is not set. Please note, the following
query is not equivalent:
Full Query Language Syntax
The Java EE 5 Tutorial · September 2007
754