[英]Sort String column which has numbers and Alphabets( Oracle SQL)
I want to sort a string column which can include both numbers and alphabets. 我想对可以同时包含数字和字母的字符串列进行排序。
SQL Script: SQL脚本:
select distinct a.UoA, b.rating , b.tot from omt_source a left join
wlm_progress_Scored b
on a.UoA = b.UoA
where a.UoA in (select UoA from UserAccess_dev
where trim(App_User) = lower(:APP_USER))
order by
regexp_substr(UoA, '^\D*') ,
to_number(regexp_substr(UoA, '\d+'))--);
Output I'm currently getting: 我目前得到的输出:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
23
26B
26A
27
28
30
31
32
33
34B
34A
But, I want 26
and 34
to be in this order 但是,我希望26
和34
依次排列
26A
26B
34A
34B
Any suggestion will be much helpful Thanks 任何建议都会有很大帮助
If your first order by clause ensures that the primary sort order is based on the numerical component of the UoA field, then your second order clause could actually be just the UoA field itself. 如果您的第一顺序子句确保主要排序顺序基于UoA字段的数字部分,那么您的第二顺序子句实际上可能只是UoA字段本身。 Ie 即
order by
regexp_substr(UoA, '^\D*'), UoA;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.