简体   繁体   English

mysql 条件 'equal' 显示条件 'like' 属性

[英]mysql condition 'equal' shows condition 'like' attributes

select * from order_info where order_id = 48;

The mysql command show above is a very simple sentence, but the result below seems not to meet my expectation, it is more similar to like condition.上面的mysql命令show是一句很简单的语句,但是下面的结果好像不符合我的预期,更像是like条件。 retrieval result检索结果

I don't know if the type of field may affect the result as the field 'order_id' is varchar type.我不知道字段类型是否会影响结果,因为字段 'order_id' 是 varchar 类型。 When I change the condition to " where order_id = '48' ", It meets my expectation.当我将条件更改为“ where order_id = '48' ”时,它符合我的期望。

Can anyone tell me why is this case?谁能告诉我为什么会这样? Why conditon 'equal' show unexpected outcomes?为什么条件“相等”会出现意想不到的结果?

I expect the result should be empty as the table does not have the record whose order_id is equal to 48.我希望结果应该为空,因为表中没有 order_id 等于 48 的记录。

Consider this -考虑这个 -

SELECT CAST('48KKKK' AS INT);

You might expect it to fail, it doesn't and the result is 48. Your query is implicitly converting order id before comparison because you are comparing to an integer so the result of your query is correct and it's a gotcha to remember..您可能认为它会失败,但事实并非如此,结果是 48。您的查询在比较之前隐式转换订单 ID,因为您正在与整数进行比较,因此您的查询结果是正确的,这是一个需要记住的陷阱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM