型変換

CAST関数は、あるデータ型の値を別のデータ型に変換するために使用されます。

CAST
記述

CAST ( 変換する値 AS 変換する型 )

mysql> SELECT CAST(123 AS DATE);
+-------------------+
| CAST(123 AS DATE) |
+-------------------+
| 2000-01-23        |
+-------------------+
1 row in set (0.00 sec)

mysql> SELECT CAST(123 AS TIME);
+-------------------+
| CAST(123 AS TIME) |
+-------------------+
| 00:01:23          |
+-------------------+
1 row in set (0.00 sec)

mysql> SELECT CAST(123 AS DATETIME);
+-----------------------+
| CAST(123 AS DATETIME) |
+-----------------------+
| 2000-01-23 00:00:00   |
+-----------------------+
1 row in set (0.00 sec)