如何在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 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短