mysql查询中str_to_date函数返回null的原因
在mysql中执行如下查询时,别名temp返回null:
select str_to_date(plan_start_time, '%h:%i:%s') as temp ,plan_start_time from base_stop_calendar
其中plan_start_time是varchar类型。
原因分析:
从提供的代码和错误提示中可以看出,str_to_date函数的格式化字符串'%h:%i:%s'中包含小写字母'h',而plan_start_time字段中的时间格式使用的是大写字母'h'。这使得str_to_date函数无法正确解析字段中的时间值,从而返回null。
解决方法:
将格式化字符串中的'h'改为'h',确保与plan_start_time字段中的时间格式一致。
修改后的查询代码:
select str_to_date(plan_start_time, '%h:%i:%s') as temp ,plan_start_time from base_stop_calendar
这样,str_to_date函数就能正确解析时间值,temp也不会再返回null。
以上就是MySQL STR_TO_DATE函数返回NULL的原因是什么?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号