发生这种情况时,我正在尝试一些值。
创建表格
mysql> create table someName (numHere varchar(4), textHere varchar(15), someMoreText varchar(10));
插入值(工作时"
周围没有1
)
mysql> insert into someName values (1, "qwerty", "asdf");
再加上一个插入符(与数字"
一起使用)
mysql> insert into someName values ("12", "texttext", "more text");
表someName
如下:
mysql> select * from somename;
+---------+----------+--------------+
| numHere | textHere | someMoreText |
+---------+----------+--------------+
| 1 | qwerty | asdf |
| 12 | texttext | more text |
+---------+----------+--------------+
用于检索数据
"
的记录时(显然它应该工作,因为它的数据类型为varchar
)mysql> select * from somename where numhere = "1";
+---------+----------+--------------+
| numHere | textHere | someMoreText |
+---------+----------+--------------+
| 1 | qwerty | asdf |
+---------+----------+--------------+
"
的情况下得到没有 varchar
的数据时,它仍然有效。mysql> select * from somename where numhere = 1;
+---------+----------+--------------+
| numHere | textHere | someMoreText |
+---------+----------+--------------+
| 1 | qwerty | asdf |
+---------+----------+--------------+
但是使用qwerty
而不使用"
来获取数据会返回错误。
为什么不使用"
时MySQL为什么将数字解释为字符串?