mysql返回结果,即使ID是错误的

发布于 2025-02-13 06:03:20 字数 1360 浏览 3 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凡尘雨 2025-02-20 06:03:22

实际上毫无疑问,但原因是此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.

且行且努力 2025-02-20 06:03:21

在ID值之后添加随机字符串时仍查询返回结果。理想情况下,它应该返回空的结果。

这意味着ID列是数字的,并且比较具有数字上下文。字符串文字被隐式转换为数字值,ID值与数字1值进行了比较。

您必须为比较设置字符串上下文。例如,您可以使用显式铸造(cast(id as char)='1abcd')或任何隐式转换(例如,whese concat(id,'''')='1abcd ')。

when adding a random string after the id value still query return result. Ideally, it should return an empty result.

This means that id column is numeric one, and the comparing have numeric context. The string literal is converted to the numeric value implicitly, and id value is compared with numeric 1 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').

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文