Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是结构myTable
myTable
---------------- |id|info1|info2| ---------------- |0 |abcde|fghij| |1 |qwert|yuopa| ----------------
这是我调用的查询:
SELECT * FROM `myTable` WHERE `id` = 'a'
它返回第一行,即
|0 |abcde|fghij|
怎么了?通常id是一个整数,但是我错误地将它输入为一个字符串,但我仍然得到了结果。
id
MySQL 尝试转换'a'为整数。该字符串不包含任何数值,因此强制转换的结果是0. 这就是 MySQL 进行强制转换的方式。
'a'
0
SELECT 0 = 'a';
上述查询返回1(TRUE)。
1
SELECT CAST('a' AS SIGNED INTEGER);
上面的查询返回0.