如何在 WHERE 比较中强制 mySQL 不将 varchar 转换为数字

How to force mySQL NOT to convert varchar to numeric in WHERE comparison

当包含类型为 varchar 的列的 table 包含可以转换为数值的数据时,例如“100”,mySQL(有帮助??)将 WHERE 字符串转换为一个数值和 returns 匹配

WHERE column = '100'
WHERE column = '100.00'
WHERE column = '100abc'
WHERE column = '100areyoukiddingme'

我只想 return 完全匹配,但不想使用 WHERE BINARY column = 因为当值不是数字时会强制进行区分大小写的搜索,这是我不想要的。我还想避免使用 REGEX 或 LIKE,因为那样会涉及 table 扫描。

搜索字符串是最终用户输入的临时值,可能是也可能不是数字,table 中的值也是如此。

除了对 PHP 中的列进行双重检查以检查该列是否确实匹配之外,我该如何测试完全匹配。像

WHERE column === '100abc'

会很好。

编辑

这不是 mySQL 的行为方式,这是我没有检查我正在测试的 table 的错误 - 该列未按预期定义为 varchar,而是 INT(11) 因此mySQL 正确地将所有字符串转换为整数。

create table t7
(   id int auto_increment primary key,
    thing varchar(100) not null
);

insert t7(thing) values ('100'),('100kidding');

select * from t7 where thing='100';
+----+-------+
| id | thing |
+----+-------+
|  1 | 100   |
+----+-------+

select * from t7 where thing='100kidding';
+----+------------+
| id | thing      |
+----+------------+
|  2 | 100kidding |
+----+------------+

select * from t7 where thing=100;
+----+------------+
| id | thing      |
+----+------------+
|  1 | 100        |
|  2 | 100kidding |
+----+------------+

你知道它是一个字符串(意味着你知道你的模式有一个 varchar)。所以,无论如何都要传递一个字符串。