CONVERT¶
Function Description¶
The CONVERT() function converts a value to the specified data type or character set.
Grammar Structure¶
> CONVERT(value, type)
or:
> CONVERT(value USING charset)
Example¶
mysql> select convert(150,char);
+-------------------------+
| cast(150 as char) |
+-------------------------+
| 150 |
+-------------------------+
1 row in set (0.01 sec)
CREATE TABLE t1(a tinyint);
INSERT INTO t1 VALUES (127);
mysql> SELECT 1 FROM
-> (SELECT CONVERT(t2.a USING UTF8) FROM t1, t1 t2 LIMIT 1) AS s LIMIT 1;
+------+
| 1 |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
limit¶
Non-numeric character types cannot be converted to numeric type
The numerical type and character type of the date format cannot be converted to Date type
Date, Datetime type cannot be converted to character type
Date and Datetime cannot convert each other