mysql字符串转换返回0 [英] mysql string conversion return 0

查看:357
本文介绍了mysql字符串转换返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么select 'aaa' =0返回1(TRUE) 如果我有一张桌子

why select 'aaa' =0 return 1 (TRUE) if i have a table like

userid | pass

user1  | pas1

如果我查询:

select from table where userid = 0 and pass =0 

它给了我所有的行吗?

推荐答案

MySQL看到'aaa'= 0并自省:

MySQL sees 'aaa' = 0 and thinks to itself:

我可以将aaa转换为整数,也可以将0转换为字符串."

"I can either convert aaa to an integer, or 0 to a string."

猜猜它是哪一个?

基本上发生的是'aaa'正在转换为整数,并且由于它不是有效的整数,所以将其强制转换为0.

Basically what's happening is that 'aaa' is being converting to an integer, and as it's not a valid integer, it casts to 0.

0 = 0当然是正确的(或true == 1).

0 = 0 is of course true (or true == 1).

我怀疑您的userid列也发生了同样的事情,尽管不知道其值/数据类型,这很难说.

I suspect the same is happening with your userid column, though without knowing its values/datatype, it's hard to say.

http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html

这篇关于mysql字符串转换返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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