在SQL中类型转换

类型转换函数CAST(xxx AS 类型) , CONVERT(xxx,类型)
可用的类型
二进制,同带binary前缀的效果 : BINARY
字符型,可带参数 : CHAR()
日期 : DATE
时间: TIME
日期时间型 : DATETIME
浮点数 : DECIMAL
整数 : SIGNED
无符号整数 : UNSIGNED

cast函数运行示例
mysql> select cast(’125e342.83′ as signed) as clm1, cast(‘foo seo 589′ as signed) as clm2,cast(’3.35′ as signed) as clm3;
+——+——+——+
| clm1 | clm2 | clm3 |
+——+——+——+
| 125 | 0 | 3 |
+——+——+——+
1 row in set, 3 warnings (0.00 sec)

猜你喜欢

转载自blog.csdn.net/weixin_43093501/article/details/98884293
今日推荐