I am trying to formulate a query in Oracle DB such that it computes the start_date value for the rows having it as null based on the numoddays , lvl (level), and the previous level's start_date column.
For an example: Linenumber 3 and item 123:
Start_date = Start_date of previous level (2) + numofdays of current row
i.e Start_date = 03-FEB-23 01:54:00 PM + 1 = 04-FEB-23 01:54:00 PM
Notice that the non-null start date can be any arbitrary date and we have to compute the subsequent null rows for that item and the trailing non-null start_date wont follow the same pattern
ie Start_date of line number 2 is 03-FEB-23 01:54:00 PM which is not equal to 24-JAN-23 01:54:00 PM + 2 (from line number 2)
Sample table code:
select 1 LineNumber, 123 item, 1 lvl, 2 numofdays, sysdate start_date from dual
union all
select 2 , 123 , 2, 2, sysdate + 10 from dual
union all
select 3 , 123 , 3, 1, null from dual
union all
select 4 , 123 , 4, 3, null from dual
union all
select 5 , 123 , 5, 2, null from dual
union all
select 6 , 345 , 1, 1, sysdate+2 from dual
union all
select 7 , 345 , 2, 2, null from dual
union all
select 8 , 345 , 3, 1, null from dual
Desired Result:
select 1 LineNumber, 123 item, 1 lvl, 2 numofdays, sysdate start_date from dual
union all
select 2 , 123 , 2, 2, sysdate + 10 from dual
union all
select 3 , 123 , 3, 1, sysdate +10 +1 from dual
union all
select 4 , 123 , 4, 3, sysdate +10 +1+3 from dual
union all
select 5 , 123 , 5, 2, sysdate +10 +3+1+2 from dual
union all
select 6 , 345 , 1, 1, sysdate+2 from dual
union all
select 7 , 345 , 2, 2, sysdate +2 +2 from dual
union all
select 8 , 345 , 3, 1, sysdate +2 +2+1 from dual
Any help would be greatly appreciated