MySQL cast()函数介绍
功能:cast()函数,将给定的值,或者给定的字段转换为指定的类型
语法:cast(value as datatype)
参数:
datatype 参数列表:
DATE | Converts value to DATE. Format: “YYYY-MM-DD” |
DATETIME | Converts value to DATETIME. Format: “YYYY-MM-DD HH:MM:SS” |
TIME | Converts value to TIME. Format: “HH:MM:SS” |
CHAR | Converts value to CHAR (a fixed length string) |
SIGNED | Converts value to SIGNED (a signed 64-bit integer) |
UNSIGNED | Converts value to UNSIGNED (an unsigned 64-bit integer) |
BINARY | Converts value to BINARY (a binary string) |
示例:
select cast(1000 as char); // 将1000转换为char类型
select cast(‘2019-07-29 05:23:26’ as date); // 2019-07-29
select cast(‘2019-07-29 05:23:26’ as time); // 05:23:26
小贴士:
convert()方法也有类似功能;
One thought on “MySQL cast()函数介绍”
求:时间间距sql怎么表达?