您可以通过使用model
子句来实现这一点,例如:
with t1(ID, Period) as(
select 1, 5 from dual union all
select 2, 3 from dual union all
select 3, 2 from dual
)
select ID
, period as hour
from t1
model
partition by (ID)
dimension by (1 as indx)
measures(period)
rules(
period[for indx from 1 to period[1] increment 1] = cv(indx)
)
SQLFiddle 演示
结果:
ID HOUR
---------- ----------
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
3 1
3 2
10 rows selected
您的insert
陈述可能如下所示:
insert into t2(id, hour)
select ID
, period
from t1
model
partition by (ID)
dimension by (1 as indx)
measures(period)
rules(
period[for indx from 1 to period[1] increment 1] = cv(indx)
)