对于同一列中具有字符和数字的列按问题排序

order by issue for column having character and number in same column

我的 table 中有一列具有两种类型的值字符和 number.I 想要按升序显示数字,而不是 order.I 试图在下面使用的降序字符:

order by case when substr(employe_info,1,1) between '0' and '9' then 1 else 2 end,
employe_info

但它使数字和字符的顺序相同(升序或降序)。

请协助

table name: test_1
columns : id number(10) , 
          employe_info (varchar 50)

数据:

id     employe_info
1      123
2      x
3      y
4      z
5      678
6      265
8      a
9      1020

期望的输出:

id   employe_info
1    123
6    265
5    678
9    1020
4    z
3    y
2    x
8    a

当你想要在特定位置输出顺序时,很难实现这样的 ordering,但你可以使用 decode 并实现如下:

 SELECT *
    FROM test1
ORDER BY DECODE (SUBSTR (employe_info, 1, 1),
                 '0', 1,
                 '1', 1,
                 '2', 1,
                 '3', 1,
                 '4', 1,
                 '5', 1,
                 '6', 1,
                 '7', 1,
                 '8', 1,
                 '9', 1,
                 'z', 2,
                 'y', 3,
                 'x', 4,
                  --Add here more alphabet as per your desired position
                 5);

注意:此解决方案是根据提供的数据集。如果您添加更多数据,那么您需要 extend 解码中 alphabet 的位置。