赞
踩
简单介绍
cast()函数: 强制数据类型转换
cast()函数用法: cast(字段名 as 转换的类型)
实际应用
例:
表名:table 字段名:data (data 为 2019-09-16 18:53:00)
1. 转换为整型(int)
select cast (data as signed) as data from table;
查询结果为:20190916185300
2. 转换为字符型(char)
select cast(data as char) as data from table;
查询结果为:2019-09-16 18:53:00
3. 转换为日期时间型(datetime)
select cast(data as datetime) as data from table;
查询结果为:2019-09-16 18:53:00
5. 转换为日期型(date)
select cast(data as date) as data from table;
查询结果为:2019-09-16
7. 转换为时间型(time)
select cast(data as time) as data from table;
查询结果为:18:53:00
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。