MySQL CAST() Function
Example
Convert a value from one datatype to another datatype:
SELECT
CAST("2017-08-29" AS DATE);
Try it Yourself »
Definition and Usage
The CAST() function converts a value from one datatype to another datatype.
Tip: See also the CONVERT() function.
Syntax
CAST(value AS type)
Parameter Values
Parameter | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
value | Required. The value to convert | ||||||||||||||||
type | Required. The datatype to convert to. Can be one of the following:
|
Note
- CAST(value AS BINARY) is equivalent to using the BINARY function.
Technical Details
Works in: | MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0.2 |
---|
More Examples
Example
Convert a value from one datatype to another datatype:
SELECT CAST(150 AS CHAR);
Try it Yourself »
Example
Convert a value from one datatype to another datatype:
SELECT CAST("14:06:10" AS TIME);
Try it Yourself »
Example
Convert a value from one datatype to another datatype:
SELECT CAST(5-10 AS SIGNED);
Try it Yourself »