顯然非常罕見的問題,但IMO非常惱人的和錯誤的:在MySQL尾隨空格沒有在比較中使用:MySQL的製造空白事
mysql> SELECT "A" = "A ";
+------------+
| "A" = "A " |
+------------+
| 1 |
+------------+
1 row in set (0.00 sec)
這是在以下情況下尤其有問題:
mysql> SELECT COUNT(*) FROM eq WHERE name != TRIM(name);
+------------+
| COUNT(*) |
+------------+
| 0 |
+------------+
1 row in set (0.00 sec)
mysql> UPDATE eq SET name=TRIM(name);
Query OK, 866 row affected (0.01 sec)
Rows matched: 650907 Changed: 866 Warnings: 0
有沒有辦法配置MySQL來正確對待空白?
二進制比較將防止去除尾部空格的:'SELECT BINARY '一個'= BINARY 'A';'' –