To cast a value as a BIGINT in MySQL, we can use the CAST() function. As part of our MySQL Support, Bobcares provides answers to all of your questions.
How to Cast as Bigint in MySQL?
In MySQL, BIGINT is a data type used to store large integer values. It allows us to store integers ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. This makes it suitable for cases where we need to store very large integer values. It is also widely supported across different versions of MySQL and is commonly used in various apps.
So, in order to cast a type to a BIGINT in MySQL, we can use the CAST() operator along with the CONV() function. Let’s see how:
First, let’s say we have a hexadecimal value (e.g., ‘AB5’) and we want to convert it to a decimal (base 10) BIGINT.
The syntax is:
SELECT CAST(CONV('ColumnName', 16, 10) AS UNSIGNED INTEGER) as anyAliasName FROM TableName;
For example, suppose we have a table named tableA with a column named Value. Here, we want to convert the values in this column from hexadecimal to decimal BIGINT.
Here’s how we do it:
1. Initially, we must create a table:
CREATE TABLE tableA ( Id INT NOT NULL AUTO_INCREMENT, Value VARCHAR(100), PRIMARY KEY(Id) );
2. Then, insert some records into the table by using the following commands:
INSERT INTO tableA(Value) VALUES ('AB5'); INSERT INTO tableA(Value) VALUES ('55244A5562C5566354'); INSERT INTO tableA(Value) VALUES ('4546575765ABD78'); INSERT INTO tableA(Value) VALUES ('5979787DEFAB'); INSERT INTO tableA(Value) VALUES ('86868686856ABD');
3. Now, we want to convert the hexadecimal values in the Value column to decimal BIGINT. We can do this with the following code:
SELECT CAST(CONV(Value, 16, 10) AS UNSIGNED INTEGER) as BigNumber FROM tableA;
This query will convert the hexadecimal values in the Value column to decimal BIGINT and display them as BigNumber. This simplifies the process of changing hexadecimal values to decimal BIGINT in MySQL.
[Looking for a solution to another query? We are just a click away.]
Conclusion
BIGINT is a helpful data type in MySQL that can handle very large integer values over a broad range, providing efficient and flexible data handling and storing. To sum up, our Support team went over the MySQL Bigint Cast details in this article.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments