MySQL层比较函数的调用方式
发表于:2024-10-11 作者:千家信息网编辑
千家信息网最后更新 2024年10月11日,这篇文章主要介绍"MySQL层比较函数的调用方式",在日常操作中,相信很多人在MySQL层比较函数的调用方式问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"MySQL层比
千家信息网最后更新 2024年10月11日MySQL层比较函数的调用方式
这篇文章主要介绍"MySQL层比较函数的调用方式",在日常操作中,相信很多人在MySQL层比较函数的调用方式问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"MySQL层比较函数的调用方式"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
一、问题来源
最近遇到一个日期比较的问题如下:
root@localhost:test:10:25:48>select from_unixtime(1596680255);+---------------------------+| from_unixtime(1596680255) |+---------------------------+| 2020-08-06 10:17:35 |+---------------------------+1 row in set (0.00 sec)root@localhost:test:10:25:52>select from_unixtime(1596680255,'%Y-%m-%d') < '2020-08-1';+----------------------------------------------------+| from_unixtime(1596680255,'%Y-%m-%d') < '2020-08-1' |+----------------------------------------------------+| 1 |+----------------------------------------------------+1 row in set (2.70 sec)root@localhost:test:10:25:59>select from_unixtime(1596680255) < '2020-08-1';+-----------------------------------------+| from_unixtime(1596680255) < '2020-08-1' |+-----------------------------------------+| 0 |+-----------------------------------------+1 row in set (2.36 sec)
按理来说from_unixtime(1596680255,'%Y-%m-%d') < '2020-08-1' 应该是false才对,但是返回为true,因此怀疑为字符串比较的方式
二、问题验证
首先关闭gtid通过create table as 来验证一下字段类型如下:
create table testit951asselect from_unixtime(1596678161,'%Y-%m-%d') as "tt"create table testit952asselect from_unixtime(1596678161) as "tt"
通过这种方式发现两种建表字段为varchar和datetime类型。通过源码验证可以看到如下:
Breakpoint 5, Arg_comparator::compare_string (this=0x7fffe40167c0) at /cdh/mysqldebug/percona-server-5.7.29-32/sql/item_cmpfunc.cc:16721672 if ((res1= (*a)->val_str(&value1)))(gdb) cContinuing.Breakpoint 4, Arg_comparator::compare_datetime (this=0x7fffe40164c8) at /cdh/mysqldebug/percona-server-5.7.29-32/sql/item_cmpfunc.cc:15091509 THD *thd= current_thd;(gdb) cContinuing.
可以看到内部通过了string和datetime两种类型来比较。因此得到证明。最后留下比较函数的位置:
Item_cmpfunc.cc
到此,关于"MySQL层比较函数的调用方式"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
方式
函数
问题
学习
类型
验证
字段
更多
帮助
实用
接下来
位置
字符
字符串
文章
方法
日期
来源
源码
理论
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网拍秀软件开发
我国网络安全吗
计算服务器配置
软件开发vpn广告词
管理软件开发工程师
深圳纺织外贸软件开发
智能科技+互联网企业
网络安全密钥换成
服务器数据库账号怎么连接
江苏中帮互联网科技有限公司
天朗软件开发
银行外包软件开发岗好不好
不良反应数据库查询
软件开发简历如何介绍项目
河南光讯网络技术有限公司
电信网络技术岗的认识
枣庄市网络安全知识
如何给服务器挂马
服务器升级之后无法上网
灵武办公软件开发有什么优点
大华视频存储服务器带电拔出硬盘
数据库设置默认值无效
邯郸第三方软件开发机构
湖南长银58软件开发
网络安全问题小论文
青岛李沧软件开发学习
幽暗沼泽服务器
研究癌症的大数据库
网络技术优化学习
河南正数网络技术公司