您的位置:首页 > 数据库 > MySQL

MySQL 中空格大小写不敏感

2013-07-02 00:00 393 查看

MySQL 中空格大小写不敏感

..............................

MySQL 对字符串的后置空格是不敏感的,前置空格敏感

'dd'
,
'dd '
,用
select * from t_list where str='dd';
获取这两个结果(说明MySQL查询的时候,mysql有做righttrim的操作)

' dd'
,
'dd'
,用
select * from t_list where str='dd';
获取这第二个结果(说明MySQL前置空格不敏感)

'dd'
,
'dd '
,用
select str,LENGTH(str) from t_list;
结果为
2,3
,(说明查询结果中,空格的是包含在其中的。)

解决方法在字段前面添加 binary 关键字。
'dd'
,
'dd '
select str,LENGTH('dd','dd ',) from t_list where str=Binary('dd');
获取结果
'dd',2


这篇文章比较详细,可以参考这篇文章
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  MySQL 空格