简体   繁体   English

Oracle sql按字符顺序排序

[英]Oracle sql order by with character in order

Good day, Maybe someone can help me , i want to get n select output on oracle sql , but when i order by it is not correct. 美好的一天,也许有人可以帮助我,我想在oracle sql上获取n select输出,但是当我通过它订购时不正确。

code_order
1.
2.
2.1
3.
4.2
10.1
10.0
21.
21.1
23.
31.

it needs to be ordered numeric and all values has a full stop in . 需要将其排序为数字,并且所有值中都有一个句号.

any ideas?? 有任何想法吗??

Thanx, but i see that some values can contain non numeric values as well like C,B etc. 感谢,但是我看到一些值可以包含非数字值,例如C,B等。

                    1. 7C. 7C。 40. 50. 51. 6. 40. 50. 51. 6。
Table outline : 表大纲:

code_order is varchar2 code_order为varchar2

使用order by to_number(code_order)

    with
    val as
    (
      SELECT '1.' as c FROM dual
      union all
      SELECT '2.' as c FROM dual
      union all
      SELECT '3.' as c FROM dual
      union all
      SELECT '2.1' as c FROM dual
      union all
      SELECT '4.2' as c FROM dual
      union all
      SELECT '10.1' as c FROM dual
      union all
      SELECT '21.' as c FROM dual
      union all
      SELECT '10.0' as c FROM dual
      union all
      SELECT '21.1' as c FROM dual
      union all
      SELECT '23.' as c FROM dual
      union all
      SELECT '31.' as c FROM dual
    )
SELECT c FROM val
order by to_number(regexp_replace(c, '^(\d+)\..*$', '\1'))
    ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM