Anda dapat membuat pernyataan generator baris menggunakan CONNECT BY LEVEL
sintaks, gabungkan silang dengan produk yang berbeda di tabel Anda, lalu gabungkan di luar ke tabel harga Anda. Sentuhan terakhir adalah menggunakan LAST_VALUE
fungsi dan IGNORE NULLS
untuk mengulangi harga hingga nilai baru ditemukan, dan karena Anda menginginkan tampilan, dengan CREATE VIEW
pernyataan:
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;