mysql - 与 MySQL 中尾随空格的比较

标签 mysql sql

此 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.

enter image description here

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/

相关文章:

php - 帮助处理棘手的 MySQL 查询

Windows 上 Docker 中的 MySQL : World-writable files ignored

php - 如何在 SQL INSERT 语句中使用 PHP/HTML 中的变量

MySQL 在搜索 'ずる' 时返回 'する'(日语)

java - 如果某些值不存在则插入到表中

android - 我正在使用 Realm 数据库并且它没有外键..有没有其他解决方案?

MySQL 查询我所有(接受的) friend 的列表

mysql - 如何从表中获取value1的最大值,其中value1和value2字段忽略value2字段

sql - 在 Informix 的存储过程中传递参数 null

sql - 将 Sum() 与多个 where 子句结合使用