我有一个Spring Boot应用程序。使用JdbcTemplate访问Oracle DB
我正在处理Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
我正在使用多个连接的查询来返回由VARCHAR2(50)
类型的字段排序的某些值。我想订购这个标准:首先是字母,最后是所有数字
select vo_group.company_nr, vo_group.name name, count_vehicle, count_person, count_key_code
from vo_group
LEFT OUTER JOIN
(select vo_group.vo_group_id, count(*) count_vehicle
from vo_group, vo_group_vehicle, vehicle
where vo_group.vo_group_id=vo_group_vehicle.vo_group_id
and vo_group_vehicle.vehicle_id=vehicle.vehicle_id
and vehicle.vo_vehicle_category_id=1202270
and parent_vo_group_id=20009
group by vo_group.vo_group_id
) g_veh ON vo_group.vo_group_id=g_veh.vo_group_id
LEFT OUTER JOIN
(select vo_group.vo_group_id, count(*) count_person
from vo_group, vo_group_person, person
where vo_group.vo_group_id=vo_group_person.vo_group_id
and vo_group_person.person_id=person.person_id
and person.vo_person_category_id=1006590
and parent_vo_group_id=20900
group by vo_group.vo_group_id
) g_pers ON vo_group.vo_group_id=g_pers.vo_group_id
LEFT OUTER JOIN
(select vo_group.vo_group_id, count(*) count_key_code
from vo_group, vo_group_person, key_code
where vo_group.vo_group_id=vo_group_person.vo_group_id
and parent_vo_group_id=20090
and vo_group_person.person_id = key_code.person_id
group by vo_group.vo_group_id
) g_key ON vo_group.vo_group_id=g_key.vo_group_id
where parent_vo_group_id=20900
order by name
这给了我这个结果:
01411 Distribution Iberia Telecom
101412 Distribution Iberia Power
101440
101545 TDK - Airport Systems
101563 TDK - Waterways North
101564 TDK - Waterways Technics North
101565 TDK - Marine Technics
101590
101593 TDK - Security Aartselaar
101594 TDK - Security Braine
101595 TDK - Security Zaragoza
101842
102441
102470
102610 TDK Panels
103330
202410
202412
202423
202431
202432
202442
202443
202480
222631 TDK Frame agreements
222632 TDK Engineering Revisions
222633 TDK Machining on site
222673
80E510
ATV Technica
BUILDINGS
Buildings - Airdselaar
Buildings - Brainesa
有没有办法返回首字母然后是数字?像
ATV Technica
BUILDINGS
Buildings - Airdselaar
Buildings - Brainesa
101411 Distribution Iberia Telecom
101412 Distribution Iberia Power
101440
101545 TDK - Airport Systems
101563 TDK - Waterways North
101564 TDK - Waterways Technics North
101565 TDK - Marine Technics
101590
101593 TDK - Security Aartselaar
101594 TDK - Security Braine
101595 TDK - Security Zaragoza
101842
102441
102470
102610 TDK Panels
103330
202410
202412
202423
202431
202432
202442
202443
202480
222631 TDK Frame agreements
222632 TDK Engineering Revisions
222633 TDK Machining on site
222673
80E510
答案 0 :(得分:2)
with tab as(
select '11' as name from dual union all
select '11 a' from dual union all
select '11 b' from dual union all
select 'aa 11' from dual union all
select 'aa' from dual union all
select 'aaaa t' from dual union all
select 'bbbb 23' from dual union all
select '32' from dual
)
select col, regexp_substr(name, '[^[:digit:]]*')
from tab
order by regexp_substr(name, '[^[:digit:]]*'),
name;
regexp_substr 修剪前导数字从列的开头获取所有非数字字符串。
看到结果,我让那里的列看到regexp表达式的值:
name REGEXP_SUBSTR(name,'[^[:DIGIT:]]*')
aa aa
aa 11 aa
aaaa t aaaa t
bbbb 23 bbbb
11 null
11 a null
11 b null
32 null