一道高级SQL题
表结构和数据如下:
ID NAME
1 E1~E4
2 F3~F9
。。。。。
要求实现如下效果:
1 E1
1 E2
1 E3
1 E4
2 F3
2 F4
2 F5
2 F6
2 F7
2 F8
2 F9
------解决方案--------------------
select id, nm
------解决方案--------------------
(level + fr_num - 1)
from (SELECT t1.id id,
regexp_substr(t1.name, '[[:alpha:]]', 1, 1) nm,
regexp_substr(t1.name, '[[:digit:]]', 1, 1) fr_num,
regexp_substr(t1.name, '[[:digit:]]', 1, 2) to_num
FROM T1)
connect by level <= to_num - fr_num + 1
and id = prior id
and prior dbms_random.value is not null;
------解决方案--------------------
select id, nm
------解决方案--------------------
(level + fr_num - 1)
from (SELECT t1.id id,
regexp_substr(t1.name, '[[:alpha:]]', 1, 1) nm,
regexp_substr(t1.name, '[0-9]+', 1, 1) fr_num,
regexp_substr(t1.name, '[0-9]+', 1, 2) to_num
FROM T1)
connect by level <= to_num - fr_num + 1
and id = prior id
and prior dbms_random.value is not null;
------解决方案--------------------