Mysql不应该选择行? [英] Mysql picking row when it shoudn't?

查看:39
本文介绍了Mysql不应该选择行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑,当我发现将值设置为 0 时实际上会选择一些行.o_o0 是数字,不是字符串...这是我不知道的事情?mysql 的某些特定功能还是我做错了什么?

I was confused, when I figured out that setting value to 0 actually picks some row. O_o 0 is number, not a string... It's something i didn't knew? Some specific feature of mysql or i'm doing something wrong?

这里是查询:

SELECT * FROM contacts WHERE owner=0

结果是:

contact_id,owner,contact
10,d9659deb29f21dcf468783f1e7f52aa2b2ab6b48,7d1d00cd5cc06c27b3bcbefa8b4aeeb16bdec14e

这里是测试转储:

-- --------------------------------------------------------
-- Host:                         127.0.0.1
-- Server version:               5.5.8 - Source distribution
-- Server OS:                    Linux
-- HeidiSQL version:             7.0.0.4053
-- Date/time:                    2012-08-02 11:05:48
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET FOREIGN_KEY_CHECKS=0 */;

-- Dumping database structure for test
CREATE DATABASE IF NOT EXISTS `test` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `test`;


-- Dumping structure for table test.contacts
CREATE TABLE IF NOT EXISTS `contacts` (
  `contact_id` int(10) NOT NULL AUTO_INCREMENT,
  `owner` varchar(40) DEFAULT '',
  `contact` varchar(40) DEFAULT '',
  PRIMARY KEY (`contact_id`),
  KEY `owner` (`owner`),
  KEY `contact` (`contact`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

-- Dumping data for table test.contacts: ~2 rows (approximately)
/*!40000 ALTER TABLE `contacts` DISABLE KEYS */;
REPLACE INTO `contacts` (`contact_id`, `owner`, `contact`) VALUES
    (9, '7d1d00cd5cc06c27b3bcbefa8b4aeeb16bdec14e', 'd9659deb29f21dcf468783f1e7f52aa2b2ab6b48'),
    (10, 'd9659deb29f21dcf468783f1e7f52aa2b2ab6b48', '7d1d00cd5cc06c27b3bcbefa8b4aeeb16bdec14e');
/*!40000 ALTER TABLE `contacts` ENABLE KEYS */;
/*!40014 SET FOREIGN_KEY_CHECKS=1 */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

推荐答案

所有者 '7d1d00cd5cc06c27b3bcbefa8b4aeeb16bdec14e' 以数字 '7...' 开头,MySQL 将此值转换为 7,我们有 7 = 0 - 错误.

The owner '7d1d00cd5cc06c27b3bcbefa8b4aeeb16bdec14e' is started with a number '7...', MySQL converts this value to 7, we have 7 = 0 - FALSE.

所有者 'd9659deb29f21dcf468783f1e7f52aa2b2ab6b48' 以字符 'd...' 开头,MySQL 将此值转换为 0,因此 0 = 0 - TRUE.

The owner 'd9659deb29f21dcf468783f1e7f52aa2b2ab6b48' is started with a char 'd...', MySQL converts this value to 0, so 0 = 0 - TRUE.

这就是 MySQL 将字符串转换为数字的方式.

This is how MySQL converts strings to numbers.

这篇关于Mysql不应该选择行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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