与MySQL中的尾随空格比较 [英] Comparison with trailing spaces in MySQL

查看:181
本文介绍了与MySQL中的尾随空格比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此SQL查询:

select c1 from table where c1='';

返回MySQL中具有c1=' '(一个空格)的行.

returns rows that have c1=' ' (one empty space) in MySQL.

这是故意的还是错误?

请检查SQL Fiddle链接此处,以及SELECT查询无所谓.

please check SQL Fiddle link here, and the number of spaces in SELECT query doesn't matter.

推荐答案

在文档中全部进行了说明.我在这里引用了要点.但我建议阅读完整的 文档 >

It's all stated there in the documentation. I've quoted the important points here. But I would suggest to go through the full documentation

VARCHAR值在存储时不会被填充.尾随空格 在存储和检索值时保留,符合 标准SQL.

VARCHAR values are not padded when they are stored. Trailing spaces are retained when values are stored and retrieved, in conformance with standard SQL.

另一方面,CHAR值在存储时会被填充,但是 检索时会忽略尾随空格.

On the other hand, CHAR values are padded when they are stored but trailing spaces are ignored when retrieved.

所有MySQL归类均为PADSPACE类型.这意味着所有CHAR, 比较MySQL中的VARCHAR和TEXT值,而不考虑任何 尾随空格.在这种情况下,比较"不包括 像模式匹配运算符,后跟空格为 重要的.

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.

说明: Trailing spaces在使用比较运算符('=')比较字符串时被忽略.但是对于LIKE(pattern matching operator)

Explanation: Trailing spaces are ignored while comparing strings using comparison operator ('='). But trailing spaces are significant for LIKE (pattern matching operator)

这篇关于与MySQL中的尾随空格比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆