mysql中将int转为_mysql – 将int转换为varchar

时间:2025-02-14 07:26:15

您将需要

cast或

convert作为CHAR数据类型,没有varchar数据类型,您可以将数据转换/转换为:

select CAST(id as CHAR(50)) as col1

from t9;

select CONVERT(id, CHAR(50)) as colI1

from t9;

请参见以下SQL – 在操作中 – 在SQL Fiddle:

/*! Build Schema */

create table t9 (id INT, name VARCHAR(55));

insert into t9 (id, name) values (2, 'bob');

/*! SQL Queries */

select CAST(id as CHAR(50)) as col1 from t9;

select CONVERT(id, CHAR(50)) as colI1 from t9;

除了您尝试转换为不正确的数据类型的事实,您用于转换的语法不正确。 convert函数使用以下语句,其中expr是您的列或值:

CONVERT(expr,type)

要么

CONVERT(expr USING transcoding_name)

您的原始查询语法向后。