CONVERT

2023-12-25 08:49:42  Updated

Syntax

CONVERT(expr USING transcoding_name)
CONVERT(expr,type)

Purpose

The two syntaxes for the CONVERT() function are used for the following two purposes:

  • CONVERT(expr USING transcoding_name) changes the character set of the expression expr to the character set specified by transcoding_name.

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

    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.

    obclient> SELECT CHARSET(CONVERT('abc' USING binary));
    +--------------------------------------+
    | charset(CONVERT('abc' USING binary)) |
    +--------------------------------------+
    | binary                               |
    +--------------------------------------+
    1 row in set
    
  • Set the data type of a string to CHAR.

    obclient> SELECT CONVERT('test', CHAR);
    +-----------------------+
    | CONVERT('test', CHAR) |
    +-----------------------+
    | test                  |
    +-----------------------+
    1 row in set
    

Contact Us