廖老师好,关于students表,gender列是int类型,但是在上一节的查询和这一节的insert都是用的字符串类型,会导致insert失败的
CREATE TABLE students ( id BIGINT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, gender TINYINT(1) NOT NULL, grade INT NOT NULL, score INT NOT NULL, PRIMARY KEY(id) ) Engine=INNODB DEFAULT CHARSET=UTF8;
另外,使用where gender = ','查询的时候能成功,是因为数据类型不一致时,会发生隐式转换。如
where gender = ','
隐式转换
> select cast('M' AS DECIMAL); < 0
我打错了一个字,“使用where gender = 'M'查询的时候能成功”
where gender = 'M'
Sign in to make a reply
peterjxl
廖老师好,关于students表,gender列是int类型,但是在上一节的查询和这一节的insert都是用的字符串类型,会导致insert失败的
另外,使用
where gender = ','
查询的时候能成功,是因为数据类型不一致时,会发生隐式转换
。如