此 SQL 查询:
select c1 from table where c1='';
返回 MySQL 中具有 c1=' '
(一个空格)的行。
这是故意的还是错误?
编辑:请检查 SQL Fiddle 链接 here , SELECT
查询中的空格数无关紧要。
最佳答案
文档中都有说明。我在这里引用了要点。但我会建议通过完整的 documentation
VARCHAR values are not padded when they are stored. Trailing spaces are retained when values are stored and retrieved, in conformance with standard SQL.
On the other hand, CHAR values are padded when they are stored but trailing spaces are ignored when retrieved.
All MySQL collations are of type PADSPACE. This means that all CHAR, VARCHAR, and TEXT values in MySQL are compared without regard to any trailing spaces. “Comparison” in this context does not include the LIKE pattern-matching operator, for which trailing spaces are significant.
说明: 尾随空格
在使用比较运算符 ('=') 比较字符串时被忽略。但尾随空格对于 LIKE
(模式匹配运算符
)
关于mysql - 与 MySQL 中尾随空格的比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39572183/