如何在MySQL SELECT语句中使用CAST函数?
CAST()MySQL中的函数将任何类型的值转换为具有指定类型的值。让我们首先创建一个表-
mysql> create table castFunctionDemo -> ( -> ShippingDate date -> );
以下是使用insert命令在表中插入一些记录的查询-
mysql> insert into castFunctionDemo values('2019-01-31');
mysql> insert into castFunctionDemo values('2018-07-12');
mysql> insert into castFunctionDemo values('2016-12-06');
mysql> insert into castFunctionDemo values('2017-08-25');以下是使用select语句显示表中所有记录的查询-
mysql> select * from castFunctionDemo;
这将产生以下输出-
+--------------+ | ShippingDate | +--------------+ | 2019-01-31 | | 2018-07-12 | | 2016-12-06 | | 2017-08-25 | +--------------+ 4 rows in set (0.00 sec)
这是cast()在MySQLselect语句中正确使用函数的查询-
mysql> select CAST(ShippingDate AS CHAR(12)) as Conversion FROM castFunctionDemo;
这将产生以下输出-
+------------+ | Conversion | +------------+ | 2019-01-31 | | 2018-07-12 | | 2016-12-06 | | 2017-08-25 | +------------+ 4 rows in set (0.00 sec)
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短