当前位置:网站首页>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
边栏推荐
- Website construction process
- shell脚本专题(07):文件由cfs到bos
- How to record and analyze your alchemy process - use notes of the visual artifact Wandb [1]
- 网站建设流程
- From ordinary advanced to excellent test/development programmer, all the way through
- LabVIEW 使用VISA Close真的关闭COM口了吗
- 有序双向链表的实现。
- openresty 动态黑白名单
- Keras deep learning practice - traffic sign recognition
- 分享一个适用于MCU项目的代码框架
猜你喜欢
随机推荐
18、分布式配置中心nacos
【1374. 生成每种字符都是奇数个的字符串】
PanGu-Coder:函数级的代码生成模型
Creo5.0 rough hexagon is how to draw
【木棉花】#夏日挑战赛# 鸿蒙小游戏项目——数独Sudoku(3)
数据库系统原理与应用教程(072)—— MySQL 练习题:操作题 121-130(十六):综合练习
app直播源码,点击搜索栏自动弹出下拉框
win10,在proe/creo中鼠标中键不能放大缩小
What should I do if the Win11 campus network cannot be connected?Win11 can't connect to campus network solution
【周赛复盘】LeetCode第304场单周赛
PROE/Croe如何编辑已完成的草图,让其再次进入草绘状态
Win11如何开启剪贴板自动复制?Win11开启剪贴板自动复制的方法
有点奇怪!访问目的网址,主机能容器却不行
MySQL中超键、主键及候选键的区别是什么
MySQL开发技巧——存储过程
Creo5.0草绘如何绘制正六边形
Greenplum数据库源码分析——Standby Master操作工具分析
What are the application advantages of SaaS management system?How to efficiently improve the digital and intelligent development level of food manufacturing industry?
LabVIEW 使用VISA Close真的关闭COM口了吗
18. Distributed configuration center nacos









