mysql返回结果,即使ID是错误的
在ID值仍然查询返回结果之后,我将面临问题。
理想情况下,它应该返回一个空的结果。
mysql> select * from pricelists where id = '1abcd';
+----+---------+--------+--------------+--------------+---------------------+-----+-------------------+--------+-------------+--------------------+----------------+------------+---------------------+---------------------+---------------+
| id | name | markup | routing_type | quality_base | initially_increment | inc | shadow_billing_id | status | reseller_id | pricelist_id_admin | routing_prefix | call_count | creation_date | last_modified_date | decimal_value |
+----+---------+--------+--------------+--------------+---------------------+-----+-------------------+--------+-------------+--------------------+----------------+------------+---------------------+---------------------+---------------+
| 1 | default | 0 | 0 | 1 | 0 | 60 | 0 | 0 | 0 | 0 | | 0 | 2016-07-25 00:00:00 | 2022-07-06 10:36:31 | 4 |
+----+---------+--------+--------------+--------------+---------------------+-----+-------------------+--------+-------------+--------------------+----------------+------------+---------------------+---------------------+---------------+
1 row in set, 1 warning (0.00 sec)
I am facing an issue when adding a random string after the id value still query return result.
Ideally, it should return an empty result.
mysql> select * from pricelists where id = '1abcd';
+----+---------+--------+--------------+--------------+---------------------+-----+-------------------+--------+-------------+--------------------+----------------+------------+---------------------+---------------------+---------------+
| id | name | markup | routing_type | quality_base | initially_increment | inc | shadow_billing_id | status | reseller_id | pricelist_id_admin | routing_prefix | call_count | creation_date | last_modified_date | decimal_value |
+----+---------+--------+--------------+--------------+---------------------+-----+-------------------+--------+-------------+--------------------+----------------+------------+---------------------+---------------------+---------------+
| 1 | default | 0 | 0 | 1 | 0 | 60 | 0 | 0 | 0 | 0 | | 0 | 2016-07-25 00:00:00 | 2022-07-06 10:36:31 | 4 |
+----+---------+--------+--------------+--------------+---------------------+-----+-------------------+--------+-------------+--------------------+----------------+------------+---------------------+---------------------+---------------+
1 row in set, 1 warning (0.00 sec)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上毫无疑问,但原因是此ID列是一个int列,并且您的条件中的值会自动解析为int。因此,它的“ 1”最终。
Its actually no question, but the reason is that this id column is an int column and the value in your condition is automatically parsed to int. So its "1" in the end.
这意味着
ID
列是数字的,并且比较具有数字上下文。字符串文字被隐式转换为数字值,ID
值与数字1
值进行了比较。您必须为比较设置字符串上下文。例如,您可以使用显式铸造(
cast(id as char)='1abcd'
)或任何隐式转换(例如,whese concat(id,'''')='1abcd '
)。This means that
id
column is numeric one, and the comparing have numeric context. The string literal is converted to the numeric value implicitly, andid
value is compared with numeric1
value.You must set string context for the compare. For example, you may use explicit CAST (
where CAST(id AS CHAR) = '1abcd'
) or any implicit convertion (for example,where CONCAT(id, '') = '1abcd'
).