需求:
item cnt
A 4
B 3
C 3
得到结果:
item
A1
A2
A3
A4
B1
B2
B3
C1
C2
C3
语句:
with t as(
select 'A' item,4 cnt from dual
union all
select 'B',3 from dual
union all
select 'C',3 from dual
)
select t.item || rn item
from t,
(select rownum rn
from dual
connect by rownum <= (select max(cnt) from t)) t1
where t.cnt >= t1.rn
order by item, rn
ITEM
-----------------------------------------
A1
A2
A3
A4
B1
B2
B3
C1
C2
C3
10 rows selected
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26918004/viewspace-752730/
,如需转载,请注明出处,否则将追究法律责任。