- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert varchar to unsigned integer in MySQL
To convert varchar to unsigned integer, use CAST() function. Let us first create a table −
mysql> create table DemoTable868(Amount varchar(100)); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable868 values('781'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable868 values('990'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable868 values('1002'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable868 values('560'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable868 values('890'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable868 values('9890'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable868 values('8723'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable868;
This will produce the following output −
+--------+ | Amount | +--------+ | 781 | | 990 | | 1002 | | 560 | | 890 | | 9890 | | 8723 | +--------+ 7 rows in set (0.00 sec)
Following is the query to convert varchar to unsigned integer −
mysql> select cast(Amount as unsigned) AS Amount from DemoTable868 order by Amount DESC;
This will produce the following output −
+--------+ | Amount | +--------+ | 9890 | | 8723 | | 1002 | | 990 | | 890 | | 781 | | 560 | +--------+ 7 rows in set (0.01 sec)
- Related Articles
- Convert Decimal to equivalent 8-bit unsigned integer in C#
- Convert varchar to date in MySQL?
- Convert Decimal to the equivalent 64-bit unsigned integer in C#
- Is there a way to convert Integer field into Varchar without losing data in MySQL?
- Convert string (varchar) to double in MySQL
- Convert string (varchar) to timestamp format in MySQL?
- Convert VARCHAR data to MySQL date format?
- Convert VARCHAR Date to a different format in MySQL?
- Convert from varchar to datetime and compare in MySQL?
- How to convert varchar “time” to real time in MySQL?
- Convert the value of the specified Decimal to the equivalent 16-bit unsigned integer in C#
- Searching for an integer value in a varchar field in MySQL?
- ConvertDecimal to equivalent 32-bit unsigned integer in C#
- MySQL query to copy IP address from varchar column to integer in the same table?
- Difference between signed and unsigned integer in Arduino

Advertisements