Mega Code Archive

 
Categories / MySQL Tutorial / Cast Functions Operators
 

The cast functions are useful when you want to create a column with a specific type in a CREATE SELECT statement.

mysql> mysql> CREATE TABLE new_table SELECT CAST('2000-01-01' AS DATE); Query OK, 1 row affected (0.08 sec) Records: 1  Duplicates: 0  Warnings: 0 mysql> mysql> select * from new_table; +----------------------------+ | CAST('2000-01-01' AS DATE) | +----------------------------+ | 2000-01-01                 | +----------------------------+ 1 row in set (0.00 sec) mysql> mysql> drop table new_table; Query OK, 0 rows affected (0.00 sec)