Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cast/Convert BigInt to Varchar in MySQL

Tags:

mysql

How might I Cast/Convert BigInt to Varchar in MySQL?

like image 753
InfZero Avatar asked Nov 24 '11 15:11

InfZero


People also ask

What is CAST () in MySQL?

The CAST() function converts a value (of any type) into the specified datatype.

How do I CAST a string in MySQL?

The CAST() function in MySQL is used to convert a value from one data type to another data type specified in the expression. It is mostly used with WHERE, HAVING, and JOIN clauses. This function is similar to the CONVERT() function in MySQL. It converts the value into DATE datatype in the "YYYY-MM-DD" format.

How do I CAST an int in MySQL?

To cast VARCHAR to INT, we can use the cast() function from MySQL. Here is the syntax of cast() function. For our example, we will create a table with the help of create command. Display all records with the help of select statement.


2 Answers

mysql> select  Cast( 12345678901234567890 as char) ;
+-------------------------------------+
| Cast( 12345678901234567890 as char) |
+-------------------------------------+
| 12345678901234567890                | 
+-------------------------------------+
like image 185
ajreal Avatar answered Oct 02 '22 00:10

ajreal


I think you can't cast to varchar, try char instead. Or are you trying to modify the type of an existing field of a table? Then you have to do for example:

ALTER TABLE MODIFY COLUMN mycolumn varchar(50);

like image 24
golimar Avatar answered Oct 02 '22 00:10

golimar