How to convert a bigint to a varchar in MySQL?

In MySQL, you can use the CAST function to convert data from bigint type to varchar type. The specific syntax is as follows:

SELECT CAST(column_name AS varchar(length)) FROM table_name;

In which, column_name is the name of a column with bigint type, table_name is the name of the table, and length is the length to convert to varchar type.

For example, to convert the bigint column in the table to a varchar type with a length of 10, you can use the following statement:

SELECT CAST(bigint_column AS varchar(10)) FROM table_name;

Note: When performing type conversion, make sure that the target type is long enough to accommodate the data of the source type. If the target type is too short, it will result in data truncation.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds