MySQL 中的反斜杠 \\,真是太坑了!!
一、INSERT语句中有反斜杠(\)
1、实际测试
INSERT INTO `demo0526` (`id`, `text`) VALUES (null, 'D:\陈哈哈\加班');
INSERT INTO `demo0526` (`id`, `text`) VALUES (null, 'D:\\陈哈哈\\加班');
INSERT INTO `demo0526` (`id`, `text`) VALUES (null, 'D:\\\陈哈哈\\\加班');
INSERT INTO `demo0526` (`id`, `text`) VALUES (null, 'D:\\\\陈哈哈\\\\加班');
INSERT INTO `demo0526` (`id`, `text`) VALUES (null, 'D:\\\\\陈哈哈\\\\\加班');
mysql> select * from demo0526;
+----+-----------------------+
| id | text |
+----+-----------------------+
| 1 | D:陈哈哈加班 |
| 2 | D:\陈哈哈\加班 |
| 3 | D:\陈哈哈\加班 |
| 4 | D:\\陈哈哈\\加班 |
| 5 | D:\\陈哈哈\\加班 |
+----+-----------------------+
5 rows in set (0.00 sec)
2、是啥原理?
二、SELECT查询反斜杠(\)
1、实际测试
mysql> select * from demo0526;
+----+-----------------------+
| id | text |
+----+-----------------------+
| 1 | D:陈哈哈加班 |
| 2 | D:\陈哈哈\加班 |
| 3 | D:\陈哈哈\加班 |
| 4 | D:\\陈哈哈\\加班 |
| 5 | D:\\陈哈哈\\加班 |
+----+-----------------------+
mysql> SELECT * from demo0526 where text like '%\%';
Empty set (0.00 sec)
mysql> SELECT * from demo0526 where text like '%\\%';
Empty set (0.00 sec)
mysql> SELECT * from demo0526 where text like '%\\\\%';
+----+-----------------------+
| id | text |
+----+-----------------------+
| 2 | D:\陈哈哈\加班 |
| 3 | D:\陈哈哈\加班 |
| 4 | D:\\陈哈哈\\加班 |
| 5 | D:\\陈哈哈\\加班 |
+----+-----------------------+
4 rows in set (0.00 sec)
mysql> SELECT * from demo0526 where text like '%\\\\\\\\%';
+----+-----------------------+
| id | text |
+----+-----------------------+
| 4 | D:\\陈哈哈\\加班 |
| 5 | D:\\陈哈哈\\加班 |
+----+-----------------------+
2 rows in set (0.00 sec)
2、又是啥原理?
mysql> SELECT * from demo0526 where text = '\\\\';
+----+------+
| id | text |
+----+------+
| 7 | \\ |
+----+------+
1 row in set (0.00 sec)
总结
- END - 最近热文
• 微信这项功能即将下线,赶快导出数据! • 华为奇葩面试题:一头牛重800公斤一座桥承重700公斤,请问牛怎么过桥? • 985研究生组团诈骗,一个中招就关App,涉案金额超1亿,受害人遍布全国 • 请立即卸载这款 IDEA 插件
评论