示例:
'R1-R5,C1-C2,W11-W14'
将成为:
'R1,R2,R3,R4,R5,C1,C2,W11,W12,W13,W14'
答案 0 :(得分:0)
假设您的元素始终采用XN-XM
形式,其中X
为单个字符,N
和M
为整数正数且N<M
,可能需要以下内容:
with yourString(s) as ( select 'R1-R5,C1-C2,W11-W14' from dual)
select listagg( substr(s, 0, 1) || to_char( level -1 + to_number( substr(s, 2, instr(s, '-') -2 ))), ',')
within group ( order by l, level)
from (
SELECT regexp_substr(s, '[^,]+', 1, level) s, level as l
FROM yourString
CONNECT BY instr(s, ',', 1, level - 1) > 0
)
connect by level -1 + to_number( substr(s, 2, instr(s, '-') -2 )) <= to_number( substr(s, instr(s, '-') +2))
and prior sys_guid() is not null
and prior l = l
order by 1
这里使用内部CONNECT BY
将您的字符串拆分为单个区间(例如R1-R5
),并根据范围使外部区域“复制”该行。
listagg
只是根据原始字符串中的位置和范围内单个项目的值给出的顺序聚合结果字符串。