为什么将where子句中的“ 1A”标识为列名?

时间:2019-05-30 05:39:39

标签: mysql

为什么此sql无法执行?

SELECT * FROM TEST_190530 WHERE ID=1A;

我知道1A需要用引号引起来,因为它是一个字符串,例如“ WHERE ID ='1A';”。 但是我想知道原因。为什么 1A 不带引号在sql中被标识为列名?

CREATE TABLE TEST_190530
(ID VARCHAR(50));
INSERT INTO TEST_190530 VALUES('1A');
INSERT INTO TEST_190530 VALUES('1');
INSERT INTO TEST_190530 VALUES('2C');

mysql> SELECT * FROM TEST_190530 WHERE ID=1;
+----+
| ID |
+----+
| 1A |
| 1  |
+----+
2 rows in set

mysql> SHOW WARNINGS;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: '1A' |
| Warning | 1292 | Truncated incorrect DOUBLE value: '2C' |
+---------+------+----------------------------------------+
2 rows in set

mysql> SELECT * FROM TEST_190530 WHERE ID=1A;
1054 - Unknown column '1A' in 'where clause'
mysql> SHOW WARNINGS;
+-------+------+---------------------------------------+
| Level | Code | Message                               |
+-------+------+---------------------------------------+
| Error | 1054 | Unknown column '1A' in 'where clause' |
+-------+------+---------------------------------------+
1 row in set

0 个答案:

没有答案