- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
How to treat MySQL longtext as integer in MySQL query?
Let us first create a table −
mysql> create table DemoTable -> ( -> Value longtext -> ); Query OK, 0 rows affected (0.94 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('778437437447488487476464644433334'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('9998888485775775757577578585'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('8888874757757757757757575675656'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('988757757574646'); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+-----------------------------------+ | Value | +-----------------------------------+ | 778437437447488487476464644433334 | | 9998888485775775757577578585 | | 8888874757757757757757575675656 | | 988757757574646 | +-----------------------------------+ 4 rows in set (0.00 sec)
Here is the query to treat MySQL longtext as integer in query −
mysql> select * from DemoTable -> order by Value+0;
This will produce the following output −
+-----------------------------------+ | Value | +-----------------------------------+ | 988757757574646 | | 9998888485775775757577578585 | | 8888874757757757757757575675656 | | 778437437447488487476464644433334 | +-----------------------------------+ 4 rows in set (0.03 sec)
Advertisements