- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
SELECT * FROM `table_name` WHERE `column_name` = "60dsfdsf"
在 phpmyadmin 中,如果运行这个查询,那么它将从 table_name
中检索 column_name
值 60。
这里 column_name
类型是 int 和 primary。
我原以为找不到任何值,但它正在检索 column_name
值 60
这背后的原因是什么?
最佳答案
好吧,这是根据其类型转换值的 MySQL。如果该列的类型为 INT 并且传递的值包含具有数字的字符串,它将从中提取数字。
When an operator is used with operands of different types, type conversion occurs to make the operands compatible. Some conversions occur implicitly. For example, MySQL automatically converts numbers to strings as necessary, and vice versa.
所以在你的情况下,
SELECT * FROM
table_nameWHERE
column_name= "60dsfdsf"
实际上是转换为
SELECT * FROM
表名WHERE
column_name= "60"
编辑:
如果您的字符串以数字开头,则 MySql 将采用该数字。
例如。 60dsfdsf
是 60
但是,如果字符串最初有字母那么结果将是
例如。 dsfdsf60
对于 MySQL 是 0
。
所以要小心,因为每种情况的结果都不相同。更好的方法是在传递值之前转换或提取数字,然后将其发送给查询。
希望对你有帮助
关于php - Where 子句在传递未知字符串值后检索数据。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48981474/
我是一名优秀的程序员,十分优秀!