How might I Cast/Convert BigInt to Varchar in MySQL?
The CAST() function converts a value (of any type) into the specified datatype.
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.
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.
mysql> select Cast( 12345678901234567890 as char) ; +-------------------------------------+ | Cast( 12345678901234567890 as char) | +-------------------------------------+ | 12345678901234567890 | +-------------------------------------+
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With