mysql - 对带有转义字符的类似 mysql 的查询感到困惑?

标签 mysql

我有一个表有下面的数据

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/

相关文章:

mysql - 如何在LIKE Mysql中使用CONCAT_WS/GROUP_CONCAT?

mysql - 案例陈述失败

php - 从名称列表下拉表单中提取 MySQL INSERT 的 ID

mysql - 自动计算 MySQL 查询

mysql - 如何对 BigQuery 外部表进行建模以更改列结构?

mysql - 显示十六进制而不是文本的 View

mysql - 从计算和分组中获取最后的数据查询

php - 从同一个表但不同时间范围检索数据的最佳方法是什么?

mysql 将批量数据从一个表插入到另一个表

mysql - 左/右外连接是否需要 On 子句