Discuss / Java / 插入时数据类型写错了

插入时数据类型写错了

Topic source

peterjxl

#1 Created at ... [Delete] [Delete and Lock User]

廖老师好,关于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 = ','查询的时候能成功,是因为数据类型不一致时,会发生隐式转换。如

> select cast('M' AS DECIMAL);
< 0

peterjxl

#2 Created at ... [Delete] [Delete and Lock User]

我打错了一个字,“使用where  gender = 'M'查询的时候能成功”


  • 1

Reply