I have this table with date range:
| SID | StartDate | EndDate | CID | Time_Stamp |
|---|---|---|---|---|
| 1001 | 2021-04-14 | 2021-04-15 | 1002 | 2021-04-14 |
| 1003 | 2021-04-14 | 2021-04-16 | 1004 | 2021-04-14 |
What I need is to break down the dates so it would look like this.
| SID | StartDate | EndDate | CID | Time_Stamp |
|---|---|---|---|---|
| 1001 | 2021-04-14 | 2021-04-15 | 1002 | 2021-04-14 |
| 1001 | 2021-04-15 | 2021-04-15 | 1002 | 2021-04-14 |
| 1003 | 2021-04-14 | 2021-04-16 | 1004 | 2021-04-14 |
| 1003 | 2021-04-15 | 2021-04-16 | 1004 | 2021-04-14 |
| 1003 | 2021-04-16 | 2021-04-16 | 1004 | 2021-04-14 |
I have the following code but it does not break down the dates and only gives the date range.
if trunc(EndDate) > trunc(StartDate) then
lv_start_date := trunc(StartDate);
WHILE trunc(lv_start_date) <= trunc(EndDate) LOOP
insert into mytable values (SID, trunc(lv_start_date), trunc(EndDate),
CID,Time_Stamp);
commit;
lv_start_date := lv_start_date + 1;
END LOOP;
end if;
Is there any way to improve the code to get the expected result?