[SQL ] MySQL unicode LIKE 比對 % 結果不正確?
資料庫名稱:MySQL
資料庫版本:5.7.18
內容/問題描述:
> SELECT '\%b' LIKE '%\%'
這個語法在不同的 collation 結果不相同。
utf8_unicode_ci 結果為 1
utf8_general_ci 結果為 0
第一個 % 是 wildcard, 後面的 \% 視為 % 字元,這樣結果應該是 0 才正確吧?
請問為什麼使用 unicode 的時候結果會是 1 呢?
我用 cli 執行的結果如下:
mysql> SET collation_connection = utf8_unicode_ci;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT '\%b' LIKE '%\%';
+------------------+
| '\%b' LIKE '%\%' |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
mysql> SET collation_connection = utf8_general_ci;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT '\%b' LIKE '%\%';
+------------------+
| '\%b' LIKE '%\%' |
+------------------+
| 0 |
+------------------+
1 row in set (0.00 sec)
mysql> SET collation_connection = utf8mb4_unicode_ci;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT '\%b' LIKE '%\%';
+------------------+
| '\%b' LIKE '%\%' |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
mysql> SET collation_connection = utf8mb4_general_ci;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT '\%b' LIKE '%\%';
+------------------+
| '\%b' LIKE '%\%' |
+------------------+
| 0 |
+------------------+
1 row in set (0.00 sec)
mysql> SET collation_connection = utf8mb4_unicode_520_ci;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT '\%b' LIKE '%\%';
+------------------+
| '\%b' LIKE '%\%' |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.166.147.230
※ 文章網址: https://www.ptt.cc/bbs/Database/M.1499349910.A.9F3.html
※ 編輯: VdustR (140.116.247.215), 07/07/2017 09:14:23
→
07/12 09:03, , 1F
07/12 09:03, 1F
→
07/14 14:55, , 2F
07/14 14:55, 2F
→
07/14 15:01, , 3F
07/14 15:01, 3F
→
07/17 08:56, , 4F
07/17 08:56, 4F
→
07/17 18:58, , 5F
07/17 18:58, 5F
→
07/17 18:58, , 6F
07/17 18:58, 6F
→
07/17 18:59, , 7F
07/17 18:59, 7F
→
07/17 22:43, , 8F
07/17 22:43, 8F
→
06/17 22:23, , 9F
06/17 22:23, 9F
Database 近期熱門文章
PTT數位生活區 即時熱門文章