Skip to main content
Version: V1.0.0

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 expression expr to the character set specified by transcoding_name.

  • CONVERT(expr,type) converts the expression expr to the data type specified by type.

    In this usage, CONVERT(expr,type) is equivalent to CAST(expr AS type). For more information about the CAST function, 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)