如何在 MySQL 查询中将 MySQL longtext 视为整数?
让我们首先创建一个表 −
mysql> create table DemoTable -> ( -> Value longtext -> ); Query OK, 0 rows affected (0.94 sec)
使用 insert 命令在表中插入一些记录 −
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)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable;
这将生成以下输出 −
+-----------------------------------+ | Value | +-----------------------------------+ | 778437437447488487476464644433334 | | 9998888485775775757577578585 | | 8888874757757757757757575675656 | | 988757757574646 | +-----------------------------------+ 4 rows in set (0.00 sec)
以下是将 MySQL longtext 视为查询中整数的查询 −
mysql> select * from DemoTable -> order by Value+0;
这将生成以下输出 −
+-----------------------------------+ | Value | +-----------------------------------+ | 988757757574646 | | 9998888485775775757577578585 | | 8888874757757757757757575675656 | | 778437437447488487476464644433334 | +-----------------------------------+ 4 rows in set (0.03 sec)
广告