Oracle数字字符串排序

上一篇 / 下一篇  2017-02-07 10:49:41 / 个人分类:其他

Oracle数据库中假设有某个值id数字字符串,如1,2,3,4,5,6,7,8,9,10
select id from tablename order by id desc 
结果排序9是最大,
9
8
7
6
5
4
3
2
10
1
那么如果想要按照10,9,8...3,2,1这种方式打印,可以按照如下方式:
to_number(regexp_substr(id,'[0-9]*[0-9]',1)) desc


顺便记录一下:获取一个表中最大id,需要用同表嵌套查询
select id into SNO from ( select id from  tablename where id is not null order by  to_number(regexp_substr(id,'[0-9]*[0-9]',1)) desc) where  rownum <=1

TAG: Oracle 字符串

 

评分:0

我来说两句

Open Toolbar