0

美好的一天,也许有人可以帮助我,我想在 oracle sql 上获得 n 选择输出,但是当我订购时它是不正确的。

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

它需要按数字排序,并且所有值都有一个句号.

有任何想法吗??

谢谢,但我看到某些值可以包含非数值以及 C、B 等。

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

code_order 是 varchar2

4

2 回答 2

0
    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'))
    ;
于 2012-08-20T08:39:49.430 回答
0

利用order by to_number(code_order)

于 2012-08-20T07:29:17.320 回答