当前位置:网站首页>Oracle排序某个字段, 如果这个varchar2类型的字段有数字也有文字 , 怎么按照数字大小排序?
Oracle排序某个字段, 如果这个varchar2类型的字段有数字也有文字 , 怎么按照数字大小排序?
2022-08-01 19:33:00 【刘贵宾】
Oracle排序某个字段, 如果这个varchar2类型的字段有数字也有文字 , 怎么按照数字大小排序?
采纳答案1:
用正则关系式来实现
select * from table_name order by to_number(translate(id, '0123456789.' || id, '0123456789.')) asc nulls last
select * from table_name order by to_number(regexp_substr(id,'[0-9]*[0-9]',1))
其他答案1:
用正则关系式来实现
select * from table_name order by to_number(translate(id, '0123456789.' || id, '0123456789.')) asc nulls last
select * from table_name order by to_number(regexp_substr(id,'[0-9]*[0-9]',1))
其他答案2:
varchar2 字段会自动把数值型转换为字符型。
字符串类型的排序和numer类型的排序是不一样的,Oracle 字符串比较大小是根据ASCII来的,字符串排序是先比较第一个字符。
ASCII对照表:
下面的列子:
SQL> create table t1(name varchar2(5));Table created.SQL> insert into t1 values(6);1 row created.SQL> insert into t1 values('a');1 row created.SQL> insert into t1 values(52);1 row created.SQL> commit;Commit complete.SQL> select * from t1 order by 1;NAME-----526a
边栏推荐
- ClassID的计算中,&表示啥意思
- When installing the GBase 8c database, the error message "Resource: gbase8c already in use" is displayed. How to deal with this?
- Win11如何开启剪贴板自动复制?Win11开启剪贴板自动复制的方法
- How to query database configuration parameters in GBase 8c, such as datestyle.What function or syntax to use?
- 通配符 SSL/TLS 证书
- CMake教程——Leeds_Garden
- 【综述专栏】IJCAI 2022 | 图结构学习最新综述:研究进展与未来展望
- [Server data recovery] Data recovery case of offline multiple disks in mdisk group of server Raid5 array
- Selenium在远程中的截图
- modbus bus module DAM-8082
猜你喜欢
Ha ha!A print function, quite good at playing!
面试必问的HashCode技术内幕
Become a Contributor in 30 minutes | How to participate in OpenHarmony's open source contributions in multiple ways?
nacos installation and configuration
文库网站建设源码分享
Win11如何开启剪贴板自动复制?Win11开启剪贴板自动复制的方法
PHP 安全最佳实践
Pytorch模型训练实用教程学习笔记:一、数据加载和transforms方法总结
Mobile Zero of Likou Brush Questions
Try compiling QT test on Allwinner V853 development board
随机推荐
在表格数据上,为什么基于树的模型仍然优于深度学习?
网络不通?服务丢包?这篇 TCP 连接状态详解及故障排查,收好了~
17. Load balancing
开源视界 | StreamNative 盛宇帆:和浪漫的人一起做最浪漫的事
Mobile Zero of Likou Brush Questions
In the background of the GBase 8c database, what command is used to perform the master-slave switchover operation for the gtm and dn nodes?
mysql自增ID跳跃增长解决方案
ExcelPatternTool: Excel form-database mutual import tool
vtk体绘制代码报错的解决办法(代码在vtk7,8,9中都能运行),以及VTK数据集网站
AcWing 797. 差分
通配符 SSL/TLS 证书
modbus bus module DAM-8082
When installing the GBase 8c database, the error message "Resource: gbase8c already in use" is displayed. How to deal with this?
经验共享|在线文档协作:企业文档处理的最佳选择
对于web性能优化我有话说!
重保特辑|拦截99%恶意流量,揭秘WAF攻防演练最佳实践
【蓝桥杯选拔赛真题47】Scratch潜艇游戏 少儿编程scratch蓝桥杯选拔赛真题讲解
MySQL中超键、主键及候选键的区别是什么
TestNG多个xml进行自动化测试
How to install voice pack in Win11?Win11 Voice Pack Installation Tutorial