mysql>
SELECT 'David!' LIKE 'David\_';
-> 0
mysql>
SELECT 'David_' LIKE 'David\_';
-> 1
To specify a different escape character, use the
mysql>
SELECT 'David_' LIKE 'David|_' ESCAPE '|';
-> 1
The escape sequence should be empty or one character long. The expression must evaluate as a
constant at execution time. As of MySQL 5.0.16, if the
enabled, the sequence cannot be empty.
The following two statements illustrate that string comparisons are not case sensitive unless one of
the operands is a binary string:
mysql>
SELECT 'abc' LIKE 'ABC';
-> 1
mysql>
SELECT 'abc' LIKE BINARY 'ABC';
-> 0
In MySQL,
[896]
LIKE
SQL
[896].)
LIKE
mysql>
SELECT 10 LIKE '1%';
-> 1
Note
Because MySQL uses C escape syntax in strings (for example, "\n" to
represent a newline character), you must double any "\" that you use in
LIKE
To search for "\", specify it as "\\\\"; this is because the backslashes are
stripped once by the parser and again when the pattern match is made,
leaving a single backslash to be matched against.
Exception: At the end of the pattern string, backslash can be specified as
"\\". At the end of the string, backslash stands for itself because there is
nothing following to escape. Suppose that a table contains the following
values:
mysql>
+--------------+
| filename
+--------------+
| C:
| C:\
| C:\Programs
| C:\Programs\ |
+--------------+
To test for values that end with backslash, you can match the values using
either of the following patterns:
mysql>
+--------------+---------------------+
| filename
+--------------+---------------------+
| C:
| C:\
| C:\Programs
| C:\Programs\ |
+--------------+---------------------+
String Comparison Functions
is permitted on numeric expressions. (This is an extension to the standard
[896]
strings. For example, to search for "\n", specify it as "\\n".
SELECT filename FROM t1;
|
|
|
|
SELECT filename, filename LIKE '%\\' FROM t1;
| filename LIKE '%\\' |
|
|
|
897
clause:
ESCAPE
NO_BACKSLASH_ESCAPES
0 |
1 |
0 |
1 |
[537]
SQL mode is
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers