Puede crear una declaración de generador de filas usando el CONNECT BY LEVEL
sintaxis, cruce con los distintos productos en su tabla, y luego únalos a su tabla de precios. El toque final es usar el LAST_VALUE
función y IGNORE NULLS
para repetir el precio hasta que se encuentre un nuevo valor, y dado que quería una vista, con CREATE VIEW
declaración:
create view dense_prices_test as
select
dp.price_date
, dp.product
, last_value(pt.price ignore nulls) over (order by dp.product, dp.price_date) price
from (
-- Cross join with the distinct product set in prices_test
select d.price_date, p.product
from (
-- Row generator to list all dates from first date in prices_test to today
with dates as (select min(price_date) beg_date, sysdate end_date from prices_test)
select dates.beg_date + level - 1 price_date
from dual
cross join dates
connect by level <= dates.end_date - dates.beg_date + 1
) d
cross join (select distinct product from prices_test) p
) dp
left outer join prices_test pt on pt.price_date = dp.price_date and pt.product = dp.product;