Mysql 中字符串用单引号还是双引号?

时间:2024-04-01 19:49:41

答案是都可以。
Mysql 中字符串用单引号还是双引号?
但是 mysql 里面有个 sql mode 叫做:ANSI_QUOTES 。这个 ANSI_QUOTES 开启后会把 双引号当作 ``。所以我们还是建议使用单引号来引用字符串。

mysql 官方文档原文解释:

ANSI_QUOTES

Treat " as an identifier quote character (like the quote character) and not as a string quote character. You can still use to quote identifiers with this mode enabled. With ANSI_QUOTES enabled, you cannot use double quotation marks to quote literal strings because they are interpreted as identifiers.

参考文档:https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html