msql like _ vs %
In MySQL, the underscore (_
) and percent sign (%
) are wildcards used in LIKE
expressions for pattern matching.
The underscore matches any single character, while the percent sign matches any sequence of zero or more characters. For example:
LIKE 'cat'
: matches any string that exactly equals'cat'
LIKE 'c_t'
: matches any string that starts with'c'
, ends with't'
, and has one character between them (e.g.,'cat'
,'cot'
,'cut'
, etc.)LIKE 'c%'
: matches any string that starts with'c'
(e.g.,'cat'
,'can'
,'cookie'
, etc.)LIKE '%at'
: matches any string that ends with'at'
(e.g.,'cat'
,'bat'
,'flat'
, etc.)LIKE '%a%'
: matches any string that contains the letter'a'
(e.g.,'cat'
,'banana'
,'apple'
, etc.)
Note that MySQL is case-insensitive by default, so LIKE 'CAT'
is equivalent to LIKE 'cat'
. However, you can change this behavior by setting the collation or using the BINARY
keyword.
标签:LIKE,04,matches,08,cat,etc,2023,any,string From: https://www.cnblogs.com/chucklu/p/17298630.html