oracle中字符型字段按数字排序ORA varchar2 按数字排序

简单粗暴:

order by to_number(字段名)
今天在转换数据时,遇到了一个主键排序的问题。字符型的主键,保存的都是数字,数据导过来以后发现数据排序都是乱的,就想着按数字规则排序。

但发现to_number总是报错,就想着里面应该是有字符存在。后来使用了正则关系式,问题解决。

以下是正则关系式的两种用法,记录下来。

select * from xtyhxx order by to_number(translate(yhid, '0123456789.' || yhid, '0123456789.')) asc nulls last


select * from xtyhxx  order by  to_number(regexp_substr(yhid,'[0-9]*[0-9]',1))

猜你喜欢

转载自blog.csdn.net/wwppp987/article/details/112553119
今日推荐