mysql如何做多类型比较? [英] How does mysql do multi-type comparison?

查看:67
本文介绍了mysql如何做多类型比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目,由于误解,我们最终将存储的 int 与 MySql 数据库中的字符串进行了比较.我进行了一些测试,它似乎有效,但我想知道 MySql 如何比较不同的数据类型.

I was working on a project and due to a miscomprehension, we ended up comparing a stored int with a string in a MySql database. I ran a few test and it seems to work but I would like to know how MySql compares different datatypes.

它是否将一个转换为另一个?如果确实如此,它会同时转换为字符串还是整数?

Does it convert one to the other? If it does does it convert both to strings or to ints?

推荐答案

Mysql 手册中有一个完整的部分专门用于此,称为 表达式求值中的类型转换.

Mysql manual has a complete section dedicated to this, called Type Conversion in Expression Evaluation.

当一个运算符与不同类型的操作数一起使用时,会发生类型转换以使操作数兼容.某些转换是隐式发生的.例如,MySQL 会根据需要自动将数字转换为字符串,反之亦然.

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.

如果将 int 与字符串进行比较,则两个值都将转换为浮点数并进行比较.

If you compare an int with a string, then both values are converted to floating point number and compared thus.

这篇关于mysql如何做多类型比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆