WITH t(period, value) as ( select '2012-03','4000' from dual union all select '2012-08','8000' from dual ) select tm.dt as period , nvl( last_value(value ignore nulls) over(order by tm.dt), last_value(value ignore nulls) over(order by tm.dt desc) ) value from ( select to_char(add_months( (select to_date(substr(min(period),1,4)||'01','yyyymm') from t ) ,level-1),'yyyy-mm') dt, level lv from dual connect by level <= 24 ) tm left outer join t on t.period = tm.dt order by dt
-- last_value 함수 쓰지 않은 쿼리 입니다. WITH t(period, value) as ( select '2012-03','4000' from dual union all select '2012-08','8000' from dual union all select '2012-11','2000' from dual ) select TA.dt as period, TB.value from ( select tm.dt , t.value , nvl(nvl2(t.value, period, (select max(period) from t where to_date(period,'yyyy-mm') < to_date(tm.dt,'yyyy-mm')) ),(select min(period) from t)) n_dt from ( select to_char(add_months( (select to_date(substr(min(period),1,4)||'01','yyyymm') from t ) ,level-1),'yyyy-mm') dt, level lv from dual connect by level <= 24 ) tm left outer join t on t.period = tm.dt order by dt ) TA left outer join t TB on TB.period = TA.n_dt order by dt