I do not understand this MySQL behaviour : if I want to display a, I can just select "a\b"
which work without problem :
mysql> select "a\b";
+-----+
| a |
+-----+
| a |
+-----+
1 row in set (0.05 sec)
But if I wnat to search a string containing a in a table using LIKE, I need to double-escape my "". Why ?
Here is an example.
We prepare a small table.
create table test ( test varchar(255) );
insert into test values ( "a\b" ) , ( "a\b\c" ) , ( "abcd" );
mysql> select * from test;
+-------+
| test |
+-------+
| a |
| ac |
| abcd |
+-------+
3 rows in set (0.05 sec)
We try to get entries beginning by "a" ...
mysql> select * from test where test LIKE "a\b%";
+------+
| test |
+------+
| abcd |
+------+
1 row in set (0.05 sec)
Why \
is just ignored there? Why I need to double-escape basckslash to get my expected result?
mysql> select * from test where test LIKE "a\\b%";
+-------+
| test |
+-------+
| a |
| ac |
+-------+
2 rows in set (0.04 sec)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…