当前位置:网站首页>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
边栏推荐
- Heavy cover special | build the first line of defense, cloud firewall offensive and defensive drills best practices
- Win11怎么安装语音包?Win11语音包安装教程
- odoo coding conventions (programming conventions, coding guidelines)
- 【webrtc】sigslot : 继承has_slot 及相关流程和逻辑
- 在表格数据上,为什么基于树的模型仍然优于深度学习?
- Gradle系列——Gradle文件操作,Gradle依赖(基于Gradle文档7.5)day3-1
- modbus总线模块DAM-8082
- modbus bus module DAM-8082
- app直播源码,点击搜索栏自动弹出下拉框
- To drive efficient upstream and downstream collaboration, how can cross-border B2B e-commerce platforms release the core value of the LED industry supply chain?
猜你喜欢

#yyds dry goods inventory# Interview must brush TOP101: the last k nodes in the linked list

Library website construction source code sharing

18. Distributed configuration center nacos

How to install voice pack in Win11?Win11 Voice Pack Installation Tutorial

力扣刷题之求两数之和

正则表达式

Win11校园网无法连接怎么办?Win11连接不到校园网的解决方法

Redis的内存淘汰策略和过期删除策略的区别是什么

Creo5.0 rough hexagon is how to draw

openresty 动态黑白名单
随机推荐
What are the application advantages of SaaS management system?How to efficiently improve the digital and intelligent development level of food manufacturing industry?
【1374. 生成每种字符都是奇数个的字符串】
{ValueError}Number of classes, 1, does not match size of target_names, 2. Tr
【软考软件评测师】基于规则说明的测试技术下篇
文库网站建设源码分享
Choosing the right DevOps tool starts with understanding DevOps
#yyds dry goods inventory# Interview must brush TOP101: the last k nodes in the linked list
cf:D. Magical Array【数学直觉 + 前缀和的和】
【木棉花】#夏日挑战赛# 鸿蒙小游戏项目——数独Sudoku(3)
MLX90640 红外热成像仪测温模块开发笔记(完整篇)
Greenplum Database Source Code Analysis - Analysis of Standby Master Operation Tools
Write code anytime, anywhere -- deploy your own cloud development environment based on Code-server
odoo coding conventions (programming conventions, coding guidelines)
升哲科技携全域数字化方案亮相2022全球数字经济大会
57:第五章:开发admin管理服务:10:开发【从MongoDB的GridFS中,获取文件,接口】;(从GridFS中,获取文件的SOP)(不使用MongoDB的服务,可以排除其自动加载类)
Selenium在远程中的截图
常用命令备查
GEE(8):使用MODIS填补由去云后的Landsat影像计算得到的NDVI数据
XSS靶场中级绕过
SQL的 ISNULL 函数