CONVERT
Syntax
CONVERT(expr USING transcoding_name)
CONVERT(expr,type)
Description
The CONVERT() function has two declarations, which are used for different purposes:
-
CONVERT(expr USING transcoding_name)converts the expressionexprto the character set specified bytranscoding_name. -
CONVERT(expr,type)converts the expressionexprto the data type specified bytype.In this usage,
CONVERT(expr,type)is equivalent toCAST(expr AS type). For more information about theCASTfunction, see CAST.
Examples
-
Change the character set of a string to
BINARY.SELECT CHARSET(CONVERT('abc' USING binary));
+--------------------------------------+
| charset(CONVERT('abc' USING binary)) |
+--------------------------------------+
| binary |
+--------------------------------------+
1 row in set (0.098 sec) -
Specify the type of a string as
CHAR.SELECT CONVERT('test', CHAR);
+-----------------------+
| CONVERT('test', CHAR) |
+-----------------------+
| test |
+-----------------------+
1 row in set (0.001 sec)