最近再使用mysql时,无意见发现,当我查询参数尾部输入若干个空格时,依然可以查出和不加空格相同的结果,像这样

   select * from wa where name='be   '
等同于
select * from wa where name='be';

  查询大量资(bai)料(du)后,基本给出的结论是这样的:如果字段是char或varchar类型,那么在字符串比较的时候MySQL使用PADSPACE校对规则,会忽略字段末尾的空格字符,这样然后我又查(搜)询(索)了一些资料,在stackoverflow上找到了一些较为专业的解答,先上地址:https://stackoverflow.com/questions/10495692/mysql-comparison-operator-spaces ,大意就是 If the length in characters of X is not equal to the length in characters of Y, then the shorter string is effectively replaced, for the purposes of comparison, with a copy of itself that has been extended to the length of the longer string by concatenation on the right of one or more pad characters, where the pad character is chosen based on CS. If CS has the NO PAD characteristic, then the pad character is an implementation-dependent character different from any character in the character set of X and Y that collates less than any string under CS. Otherwise, the pad character is a <space>. 嗯,看懂没。

  如果你有特殊需求,需要判断尾部的空格,对于字符串你可以使用  like ,如 like 'be   ',或者 使用 binary ,还有一种方法就是 使用 CHAR_LENGTH ,如  CHAR_LENGTH(name)=CHAR_LENGTH('be    ')。

  好了,就是这样,手动再见。

最新文章

  1. 关于sql server 2005存储过程的写法
  2. table 相关
  3. [转]单点登录SSO学习——CAS协议内容
  4. 【C#】VS2015开发环境的安装和配置(三)2016-08-03更新
  5. Yii源码阅读笔记(十)
  6. LNMP环境搭建(discuz论坛)
  7. 在虚拟机安装64位系统提示,此主机支持Intel VT-x,但Intel VT-x处于禁用状态
  8. 【Demo 0004】Java基础-类封装性
  9. [SQL基础教程] 4-1 数据的插入(INSERT)
  10. JavaScript贪食蛇游戏制作详解
  11. 日历组件的使用,bootstrap-datetimepicker
  12. Android--UI之ListView
  13. MySQL 5.7安装指南
  14. 03. Pandas 2| 时间序列
  15. C#-MVC开发微信应用(6)--用户分组信息管理
  16. spring 之 factory-bean &amp; factory-method
  17. python---基础知识回顾(三)(面向对象)
  18. Ubuntu18.04中配置QT5.11开发环境
  19. 5.servlet 上传文件
  20. [转] .net软件反编译笔记

热门文章

  1. WEB基础(二)--servlet的生命周期
  2. 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)
  3. js网页倒计时功能(天,时,分,秒)
  4. ElasticSearch 安装与使用
  5. Java学习|强引用,软引用,弱引用,幻想引用有什么区别?
  6. 深入解析Mysql中事务的四大隔离级别及其所解决的读现象
  7. 使用pandoc简单教程
  8. SSH原理讲解与实践
  9. 快速了解Python并发编程的工程实现(下)
  10. str类型转json,str类型转list