CONVERT

2023-10-27 09:57:43  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 the string to BINARY:

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

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

Contact Us