1、固定值转为BINARY 二进制型
SELECT CAST( 1231 AS BINARY ) AS result 运行结果:1231
2、int类型值转为CHAR 字符型
SELECT CAST(1995 AS CHAR) as result 运行结果:"1995"
3、固定时间字符串转为DATE 日期,格式为 'YYYY-MM-DD’
SELECT CAST('2019-08-29 16:50:21' as date) as result 运行结果:2019-08-29
4、固定时间字符串转为DATETIME 日期加具体的时间,格式为 'YYYY-MM-DD HH:MM:SS’
SELECT CAST('2019-08-29 16:50:21' as DATETIME) as result 运行结果:2019-08-29 16:50:21
5、固定时间字符串转为TIME 时间,格式为 'HH:MM:SS’
SELECT CAST('2019-08-29 16:50:21' as TIME) as result 运行结果:16:50:21
6、float型值通过DECIMAL 获取精度
SELECT CAST(220.23211231 AS DECIMAL(10, 3)) AS result 运行结果:220.232
7、固定字符串转为SIGNED int 型
SELECT CAST("12321" AS SIGNED ) AS result 运行结果:12321
8、固定字符串转为UNSIGNED 无符号int
SELECT CAST("12321" AS UNSIGNED ) AS result 运行结果:12321
示例:
and ( CAST(baofeidate AS DATE) >= '".$date1_search_bf."' and CAST(baofeidate AS DATE) <= '".$date2_search_bf."' )
以上就是MySQL数据类型转换函数CAST的详细内容,更多关于MySQL数据类型转换函数CAST的资料请关注九品源码其它相关文章!