时间:2021-07-01 10:21:17 帮助过:11人阅读
CHAR[(N)] 字符型
DATE 日期型
DATETIME 日期和时间型
DECIMAL float型
SIGNED int
TIME 时间型
实例1:
表table1
date:2015-11-03 15:31:26
select cast(date as signed) as date from table1;
结果如下:
date:20151103153126
select cast(date as char) as date from table1;
结果如下:
date:2015-11-03 15:31:26
实例2:
select cast(date as datetime) as date from table1;
结果如下:
date:2015-11-03 15:31:26
实例3:
select cast(date as date) as date from table1;
结果如下:
date:2015-11-03
实例4:
select cast(date as time) as date from table1;
结果如下:
date:15:31:26
这里date对应日期,time对应时间
实例5:
表table2
num:20
select cast(num as decimal(10, 2)) as num from table2
结果如下:
num:20.00
解释:decimal 数据类型最多可存储 38 个数字,所有数字都能够放到小数点的右边.decimal 数据类型存储了一个准确(精确)的数字表达法;不存储值的近似值.其中10是小数点左边和右边的数字个数之和(不包括小数点),2代表小数点右边的小数位数或数字个数.decimal(10,2)可以存储8位整数2位小数的数字.
MYSQL中,CAST函数的使用规则
标签:sel 解释 rom blog mys body cast函数 tab font