目录

MySQL CONVERT() 函数

❮ MySQL 函数

示例

将值转换为 DATE 数据类型:

SELECT CONVERT("2017-08-29", DATE);
亲自试一试 »

定义和用法

CONVERT() 函数将值转换为指定的数据类型或字符集。

提示:另请参阅投掷()功能。

语法

CONVERT( value, type)

或者:

CONVERT( value USING charset)

参数值

Parameter Description
value Required. The value to convert
type Required. The datatype to convert to. Can be one of the following:
Value Description
DATE Converts value to DATE. Format: "YYYY-MM-DD"
DATETIME Converts value to DATETIME. Format: "YYYY-MM-DD HH:MM:SS"
DECIMAL Converts value to DECIMAL. Use the optional M and D parameters to specify the maximum number of digits (M) and the number of digits following the decimal point (D).
TIME Converts value to TIME. Format: "HH:MM:SS"
CHAR Converts value to CHAR (a fixed length string)
NCHAR Converts value to NCHAR (like CHAR, but produces a string with the national character set)
SIGNED Converts value to SIGNED (a signed 64-bit integer)
UNSIGNED Converts value to UNSIGNED (an unsigned 64-bit integer)
BINARY Converts value to BINARY (a binary string)
charset Required. The character set to convert to

技术细节

工作于: 从 MySQL 4.0 开始

更多示例

示例

将值转换为 CHAR 数据类型:

SELECT CONVERT(150, CHAR);
亲自试一试 »

示例

将值转换为 TIME 数据类型:

SELECT CONVERT("14:06:10", TIME);
亲自试一试 »

示例

将值转换为 LATIN1 字符集:

SELECT CONVERT("91xjr.com" USING latin1);
亲自试一试 »

❮ MySQL 函数