Du kan oprette en rækkegeneratorsætning ved at bruge CONNECT BY LEVEL
syntaks, krydsforenet med de forskellige produkter i din tabel, og derefter ydre sammenføj det til din pristabel. Den sidste berøring er at bruge LAST_VALUE
funktion og IGNORE NULLS
for at gentage prisen indtil en ny værdi er stødt på, og da du ønskede en visning, med en CREATE VIEW
erklæring:
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;