我有一个表有下面的数据
select * from t;
+----+----------------+
| id | a |
+----+----------------+
| 1 | u5929u732b |
| 2 | \u5929\u732b |
| 3 | \\u5929\\u732b |
+----+----------------+
查询结果使用相等
select * from t where a = '\u5929\u732b';
+----+------------+
| id | a |
+----+------------+
| 1 | u5929u732b |
+----+------------+
select * from t where a = '\\u5929\\u732b';
+----+--------------+
| id | a |
+----+--------------+
| 2 | \u5929\u732b |
+----+--------------+
select * from t where a = '\\\\u5929\\\\u732b';
+----+----------------+
| id | a |
+----+----------------+
| 3 | \\u5929\\u732b |
+----+----------------+
这些结果和我预料的一样没问题,然后我用like查询结果,此时我很迷茫
# as I expected
select * from t where a like '\u5929\u732b';
+----+------------+
| id | a |
+----+------------+
| 1 | u5929u732b |
+----+------------+
# I do not understand I think it should return result of id = 2
select * from t where a like '\\u5929\\u732b';
+----+------------+
| id | a |
+----+------------+
| 1 | u5929u732b |
+----+------------+
# I think it should return result of id = 3
select * from t where a like '\\\\u5929\\\\u732b';
+----+--------------+
| id | a |
+----+--------------+
| 2 | \u5929\u732b |
+----+--------------+
那么为什么 like
查询与 equal 查询不同呢?
最佳答案
LIKE
默认使用“\”进行转义。但是你可以通过写来改变它:
select * from t where a like '\\u5929\\u732b' ESCAPE '|'
引用:
关于mysql - 对带有转义字符的类似 mysql 的查询感到困惑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44570428/