Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Filling gap rows in the query

user13168644Feb 23 2023 — edited Feb 23 2023

Hi,

I have a table that has some gaps in data. I want to fill the gaps with consecutive dates and the dollar amount from the last row. Here is the sample data

create table gap_rows ( nkey number, effective_date timestamp, base_currency varchar2(5), currency varchar2(5), fx_rate number);

insert into gap_rows VALUES( 1, to_date('1/1/2023','mm/dd/yyyy'), 'USD','CAD',2500);
insert into gap_rows VALUES( 2, to_date('1/1/2023','mm/dd/yyyy'), 'USD','GBP',2500);
insert into gap_rows VALUES( 3, to_date('1/1/2023','mm/dd/yyyy'), 'EUR','USD',2500);
insert into gap_rows VALUES( 4, to_date('1/5/2023','mm/dd/yyyy'), 'USD','GBP',2500);
insert into gap_rows VALUES( 5, to_date('1/9/2023','mm/dd/yyyy'), 'USD','CAD',2500);
insert into gap_rows VALUES( 6, to_date('1/10/2023','mm/dd/yyyy'), 'EUR','USD',2500);
insert into gap_rows VALUES( 7, to_date('1/10/2023','mm/dd/yyyy'), 'USD','GBP',2500);
insert into gap_rows VALUES( 8, to_date('1/18/2023','mm/dd/yyyy'), 'USD','CAD',2500);

So for the base_currencty “USD” and Currency “CAD” the first effective_date is 1/1/2023 and fx_rate is 2500.

The next record for base_currencty “USD” and Currency “CAD” the first effective_date is 1/9/2023 and fx_rate is 2600.

The last record for base_currencty “USD” and Currency “CAD” the first effective_date is 1/18/2023 and fx_rate is 2750.

So the query should fill the gap between 1/1/2023 and 1/9/2023 with consecutive dates and the fx_rate as 2500 with the same “nkey” number.

And then it should fill the row between 1/9/2023 and 1/18/2023 with consecutive dates and the fx_rate as 2600 with the same “nkey” number.

The consecutive dates should be listed in a new column called “FILL_DATE”.

I have attached an image with the base valus and the output values.

The same logic will be applicable to all the nkey, base_currency, and currency combinations.

Thanks

This post has been answered by Solomon Yakobson on Feb 23 2023
Jump to Answer
Comments
Post Details
Added on Feb 23 2023
2 comments
71 views