All pages
Powered by GitBook
1 of 1

Loading...

CONVERT

Convert a value to a specific type or character set. This function converts data between types or character sets using the USING keyword.

Syntax

Description

The CONVERT() and functions take a value of one type and produce a value of another type.

The type can be one of the following values:

Note that in MariaDB, INT and INTEGER are the same thing.

BINARY produces a string with the data type. If the optional length is given, BINARY(N) causes the cast to use no more than N bytes of the argument. Values shorter than the given number in bytes are padded with 0x00 bytes to make them equal the length value.

CHAR(N) causes the cast to use no more than the number of characters given in the argument.

The main difference between the and CONVERT() is that CONVERT(expr,type) is ODBC syntax while and CONVERT(... USING ...) are SQL92 syntax.

CONVERT() with USING is used to convert data between different . In MariaDB, transcoding names are the same as the corresponding character set names. For example, this statement converts the string 'abc' in the default character set to the corresponding string in the utf8 character set:

Examples

Converting a to string to permit the function to work:

See Also

This page is licensed: GPLv2, originally from

CONVERT(expr,type), CONVERT(expr USING transcoding_name)
[DECIMAL (M[,D])]
  • DOUBLE

  • FLOAT

  • INTEGER

    • Short for SIGNED INTEGER

  • SIGNED [INTEGER]

  • UNSIGNED [INTEGER]

  • TIME

  • VARCHAR (in )

  • CAST()
    BINARY
    CHAR
    DATE
    DATETIME
    BINARY
    CAST()
    CAST(expr as type)
    character sets
    BINARY
    LOWER
    Character Sets and Collations
    fill_help_tables.sql
    SELECT CONVERT('abc' USING utf8);
    SELECT enum_col FROM tbl_name 
    ORDER BY CAST(enum_col AS CHAR);
    SET @x = 'AardVark';
    
    SET @x = BINARY 'AardVark';
    
    SELECT LOWER(@x), LOWER(CONVERT (@x USING latin1));
    +-----------+----------------------------------+
    | LOWER(@x) | LOWER(CONVERT (@x USING latin1)) |
    +-----------+----------------------------------+
    | AardVark  | aardvark                         |
    +-----------+----------------------------------+
    Oracle mode