我没有找到类似的问题,可能是因为我没有找到正确的单词(英语不是我的第一语言)
问题
我有一个varchar
末尾有空格的值:"opt-193-381-markets "
当我对没有空格SELECT
的值执行 a 时,它返回相同的结果。就像 MySQL 正在修剪中的值WHERE
表定义:
mysql> desc message;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| FileId | int(11) | NO | PRI | 0 | |
| MessageKey | varchar(100) | NO | PRI | | |
| NumericKey | tinyint(1) | NO | | 0 | |
| IsObsolete | tinyint(4) | YES | MUL | NULL | |
| notes | text | YES | | NULL | |
+------------+--------------+------+-----+---------+-------+
例子:
mysql> SELECT * FROM message WHERE MessageKey = "opt-193-381-markets";
+--------+----------------------+------------+------------+-------+
| FileId | MessageKey | NumericKey | IsObsolete | notes |
+--------+----------------------+------------+------------+-------+
| 304 | opt-193-381-markets | 0 | 1 | NULL |
| 337 | opt-193-381-markets | 0 | 1 | NULL |
+--------+----------------------+------------+------------+-------+
请注意,MessageKey
末尾有空格的值,我只是要求没有空格的值。
mysql> SELECT * FROM message WHERE MessageKey = "opt-193-381-markets ";
+--------+----------------------+------------+------------+-------+
| FileId | MessageKey | NumericKey | IsObsolete | notes |
+--------+----------------------+------------+------------+-------+
| 304 | opt-193-381-markets | 0 | 1 | NULL |
| 337 | opt-193-381-markets | 0 | 1 | NULL |
+--------+----------------------+------------+------------+-------+
再增加一个空间
mysql> SELECT * FROM message WHERE MessageKey = "opt-193-381-markets ";
+--------+----------------------+------------+------------+-------+
| FileId | MessageKey | NumericKey | IsObsolete | notes |
+--------+----------------------+------------+------------+-------+
| 304 | opt-193-381-markets | 0 | 1 | NULL |
| 337 | opt-193-381-markets | 0 | 1 | NULL |
+--------+----------------------+------------+------------+-------+
逃离空间
mysql> SELECT * FROM message WHERE MessageKey = "opt-193-381-markets\ \ ";
+--------+----------------------+------------+------------+-------+
| FileId | MessageKey | NumericKey | IsObsolete | notes |
+--------+----------------------+------------+------------+-------+
| 304 | opt-193-381-markets | 0 | 1 | NULL |
| 337 | opt-193-381-markets | 0 | 1 | NULL |
+--------+----------------------+------------+------------+-------+
我也试过单引号'opt-193-381-markets'
问题
为什么我无法搜索 的确切值MessageKey
?
谢谢