MySQL 中的反斜杠 \\,真是太坑了??!

一、INSERT語(yǔ)句中有反斜杠(\)
1、實(shí)際測(cè)試
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、實(shí)際測(cè)試
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)
總結(jié)
- END - 最近熱文
? 微信這項(xiàng)功能即將下線,趕快導(dǎo)出數(shù)據(jù)! ? 華為奇葩面試題:一頭牛重800公斤一座橋承重700公斤,請(qǐng)問(wèn)牛怎么過(guò)橋? ? 985研究生組團(tuán)詐騙,一個(gè)中招就關(guān)App,涉案金額超1億,受害人遍布全國(guó) ? 請(qǐng)立即卸載這款 IDEA 插件
評(píng)論
圖片
表情
