MySql 类型转换(转载)

1.值类型转换

 

 

复制代码
select -- 数值 -> 字符
       -- char(n) n 个长度的字符,超过截取
       convert(2022, char(3)) c1, -- 202
       convert(2022, char(4)) c2, -- 2022
       convert(2022, char(5)) c3, -- 2022

       -- 字符 -> 数值
       convert('-12.56', SIGNED) s1, -- -12 有符号整数
       convert('12.56', UNSIGNED) u1, -- 12 无符号整数
       convert('12.56', decimal(3, 1)) dc1, -- 12.6 浮点数,四舍五入

       -- 字符 -> 日期
       convert('2021-05-20 13:14:00', datetime) d1, -- 日期+时间
       convert('2021-05-20 13:14:00', date) d2, -- 仅日期
       convert('2021-05-20 13:14:00', time) d3, -- 仅时间
       str_to_date('2021-05-20 13:14:00', '%Y-%m-%d %H:%i:%S') d4,
       str_to_date(now(), '%Y-%m-%d') d5, -- 日期截取
       
       -- 日期 -> 字符
       convert(now(), char) c4,
       date_format(now(), '%Y-%m-%d %H:%i:%S') c5 -- 注意大小写
  from dual;
复制代码

原文:https://blog.csdn.net/weixin_41851830/article/details/125537823

posted @   竹殇  阅读(202)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
点击右上角即可分享
微信分享提示