小编典典

忽略IN的类型转换

sql

我有问题 。

mysql> SELECT 0 IN ('a',4);
+--------------+
| 0 IN ('a',4) |
+--------------+
|            1 |
+--------------+
1 row in set, 1 warning (0.00 sec)

mysql> SELECT 1 IN ('a',4);
+--------------+
| 1 IN ('a',4) |
+--------------+
|            0 |
+--------------+
1 row in set, 1 warning (0.00 sec)

‘a’强制转换为0。如何使’a’不强制转换..?


阅读 145

收藏
2021-05-16

共1个答案

小编典典

将您要比较的值转换为字符串:

mysql> SELECT '0' IN ('a', '4');
+-----------------+
| '0' IN ('a', 4) |
+-----------------+
|               0 |
+-----------------+

mysql> SELECT '4' IN ('a', '4');
+-----------------+
| '4' IN ('a', 4) |
+-----------------+
|               1 |
+-----------------+
2021-05-16