Syntax
CONVERT(expr USING transcoding_name)
CONVERT(expr,type)
Purpose
The CONVERT() function has two declarations, each corresponding to a different use case:
CONVERT(expr USING transcoding_name)is used to convert the expressionexprto the character set specified bytranscoding_name.CONVERT(expr,type)is used to convert 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 the string to
BINARY.obclient> SELECT CHARSET(CONVERT('abc' USING binary)); +--------------------------------------+ | charset(CONVERT('abc' USING binary)) | +--------------------------------------+ | binary | +--------------------------------------+ 1 row in setSpecify the type of the string as
CHAR.obclient> SELECT CONVERT('test', CHAR); +-----------------------+ | CONVERT('test', CHAR) | +-----------------------+ | test | +-----------------------+ 1 row in set
