Difference between revisions of "LIKE Predicate"
From Lianjapedia
Yvonne.milne (Talk | contribs) m (1 revision: SQL) |
Yvonne.milne (Talk | contribs) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
==Purpose== | ==Purpose== | ||
Special predicate | Special predicate | ||
− | |||
==Syntax== | ==Syntax== | ||
<expression1> [NOT] LIKE <expression2> | <expression1> [NOT] LIKE <expression2> | ||
− | |||
==See Also== | ==See Also== | ||
− | [[SQL INSERT|INSERT]], [[SQL Predicates|PREDICATES]], [[SQL SELECT|SELECT]], [[SQL UPDATE|UPDATE]] | + | [[SQL INSERT|INSERT]], [[SQL Predicates|PREDICATES]], [[REVERSE()]], [[SQL SELECT|SELECT]], [[SQL UPDATE|UPDATE]] |
− | + | ||
==Description== | ==Description== | ||
LIKE is a special predicate to evaluate whether the specified <expression1> matches <expression2>. The <expression2> can contain the following wildcards: | LIKE is a special predicate to evaluate whether the specified <expression1> matches <expression2>. The <expression2> can contain the following wildcards: | ||
− | + | {| class="wikitable" width="100%" | |
− | + | ||
− | {| class="wikitable" | + | |
!Operator||Description | !Operator||Description | ||
|- | |- | ||
Line 24: | Line 19: | ||
|- | |- | ||
|} | |} | ||
− | |||
The optional NOT evaluates whether the specified <expression1> does not match <expression2>. | The optional NOT evaluates whether the specified <expression1> does not match <expression2>. | ||
+ | Note: to optimize WHERE <cExpression1> LIKE '%xxx' clauses, [[INDEX]] on the reverse character sequence of the relevant <cExpression1> using the [[REVERSE()]] function. | ||
==Example== | ==Example== | ||
Line 33: | Line 28: | ||
SELECT name, address, balance, cost*1.15; | SELECT name, address, balance, cost*1.15; | ||
FROM accounts; | FROM accounts; | ||
− | WHERE paid_date < date() AND name LIKE "% | + | WHERE paid_date < date() AND name LIKE "%Inc"; |
ORDER BY name, paid_date | ORDER BY name, paid_date | ||
</code> | </code> | ||
− | |||
− | |||
[[Category:Documentation]] | [[Category:Documentation]] | ||
[[Category:SQL]] | [[Category:SQL]] |
Latest revision as of 06:18, 13 April 2018
Contents
Purpose
Special predicate
Syntax
<expression1> [NOT] LIKE <expression2>
See Also
INSERT, PREDICATES, REVERSE(), SELECT, UPDATE
Description
LIKE is a special predicate to evaluate whether the specified <expression1> matches <expression2>. The <expression2> can contain the following wildcards:
Operator | Description |
---|---|
_ | Any single character |
% | Zero or more characters |
The optional NOT evaluates whether the specified <expression1> does not match <expression2>.
Note: to optimize WHERE <cExpression1> LIKE '%xxx' clauses, INDEX on the reverse character sequence of the relevant <cExpression1> using the REVERSE() function.
Example
SELECT name, address, balance, cost*1.15; FROM accounts; WHERE paid_date < date() AND name LIKE "%Inc"; ORDER BY name, paid_date