The cast functions are useful when you want to create a column with a specific type in a CREATE ... SELECT statement: : CAST « Cast Functions Operators « MySQL Tutorial






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)








17.3.CAST
17.3.1.CAST(expr AS type), CONVERT(expr,type), CONVERT(expr USING transcoding_name)
17.3.2.Converting the string 'abc' in the default character set to the corresponding string in the utf8 character set:
17.3.3.Convert blob column to char type
17.3.4.The cast functions are useful when you want to create a column with a specific type in a CREATE ... SELECT statement:
17.3.5.CAST() is useful for sorting ENUM columns in lexical order.
17.3.6.CAST() also changes the result if you use it as part of a more complex expression such as CONCAT('Date: ',CAST(NOW() AS DATE)).
17.3.7.SELECT CAST(1 AS UNSIGNED) - 2.0;