CAST
CAST (value AS dataType)
Description
Converts a value to another data type. The following conversion rules are used:
- When converting a number to a boolean, 0 is considered as false and every other value is true.
- When converting a boolean to a number, false is 0 and true is 1.
- When converting a number to a number of another type, the value is checked for overflow.
- When converting a number to binary, the number of bytes will match the precision.
- When converting a string to binary, it is hex encoded.
- A hex string can be converted into the binary form and then to a number. If a direct conversion is not possible, the value is first converted to a string.
Examples
CAST(NAME AS INT);
CAST(65535 AS BINARY);
CAST(CAST('FFFF' AS BINARY) AS INT);
Updated about 5 years ago
