当前位置:网站首页>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
边栏推荐
- shell脚本专题(07):文件由cfs到bos
- 图文详述Eureka的缓存机制/三级缓存
- MLX90640 Infrared Thermal Imager Temperature Measurement Module Development Notes (Complete)
- vtk体绘制代码报错的解决办法(代码在vtk7,8,9中都能运行),以及VTK数据集网站
- Heavy cover special | build the first line of defense, cloud firewall offensive and defensive drills best practices
- BN BatchNorm + BatchNorm的替代新方法KNConvNets
- Pytorch模型训练实用教程学习笔记:一、数据加载和transforms方法总结
- [Kapok] #Summer Challenge# Hongmeng mini game project - Sudoku (3)
- 数据库系统原理与应用教程(070)—— MySQL 练习题:操作题 101-109(十四):查询条件练习
- 有序双向链表的实现。
猜你喜欢

使用常见问题解答软件的好处有哪些?

图文详述Eureka的缓存机制/三级缓存

odoo coding conventions (programming conventions, coding guidelines)

安装win32gui失败,解决问题

内网穿透 lanproxy部署

kubernetes - deploy nfs storage class

MySQL你到底都加了什么锁?

即时通讯开发移动端弱网络优化方法总结

Shell script topic (07): file from cfs to bos

Greenplum Database Source Code Analysis - Analysis of Standby Master Operation Tools
随机推荐
升哲科技携全域数字化方案亮相2022全球数字经济大会
JS数组过滤
What should I do if the Win11 campus network cannot be connected?Win11 can't connect to campus network solution
When installing the GBase 8c database, the error message "Resource: gbase8c already in use" is displayed. How to deal with this?
Heavy cover special | build the first line of defense, cloud firewall offensive and defensive drills best practices
【综述专栏】IJCAI 2022 | 图结构学习最新综述:研究进展与未来展望
开源视界 | StreamNative 盛宇帆:和浪漫的人一起做最浪漫的事
Keras深度学习实战——交通标志识别
数据库系统原理与应用教程(070)—— MySQL 练习题:操作题 101-109(十四):查询条件练习
Win11怎么安装语音包?Win11语音包安装教程
经验共享|在线文档协作:企业文档处理的最佳选择
C#/VB.NET 从PDF中提取表格
shell脚本专题(07):文件由cfs到bos
Redis的内存淘汰策略和过期删除策略的区别是什么
mysql解压版简洁式本地配置方式
Heavy cover special | intercept 99% malicious traffic, reveal WAF offensive and defensive drills best practices
ssh & scp
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?
easyUI中datagrid中的formatter里面向后台发送请求获取数据
kubernetes-部署nfs存储类