严格来说,引号是不必要的,并且迫使MySQL执行类型转换/转换,因此浪费了CPU时间.实际上,除非您运行的是Google大小的操作,否则这种转换开销在微观上将很小.For example - I create database and a table from cli and insert some data:CREATE DATABASE testdb CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';USE testdb;CREATE TABLE test (id INT, str VARCHAR(100)) TYPE=innodb CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';INSERT INTO test VALUES (9, 'some string');Now I can do this and these examples do work (so - quotes don't affect anything it seems):SELECT * FROM test WHERE id = '9';INSERT INTO test VALUES ('11', 'some string');So - in these examples I've selected a row by a string that actually stored as INT in mysql and then I inserted a string in a column that is INT.I don't quite get why this works the way it works here. Why is string allowed to be inserted in an INT column?Can I insert all Mysql data types as strings?Is this behavior standard across different RDBMS?thanks! 解决方案 MySQL is a lot like PHP, and will auto-convert data types as best it can. Since you're working with an int field (left-hand side), it'll try to transparently convert the right-hand-side of the argument into an int as well, so '9' just becomes 9.Strictly speaking, the quotes are unnecessary, and force MySQL to do a typecasting/conversion, so it wastes a bit of CPU time. In practice, unless you're running a Google-sized operation, such conversion overhead is going to be microscopically small. 这篇关于MySQL-报价数字或没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!