Skip to Main Content

SQL & PL/SQL

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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Dynamically calculate number of days between two dates and split amounts

VladKApr 26 2010 — edited Apr 27 2010
Hello,

I have been searching for a solution for this, but didn't have any success.
I need to show amounts split by days.

I have a table that has an amount column, and start and end dates.

I need to write a query in such a way that the amounts will be broken up evenly based on the number of days between start date and end date.

For example, for this row,
insert into my_test values (1, '3-mar-2010', '7-mar-2010', 1000);

the query would return this (splitting $1,000 across 5 days)


ID Date Amount
1 '3-mar-2010' 200.00
1 '4-mar-2010' 200.00
1 '5-mar-2010' 200.00
1 '6-mar-2010' 200.00
1 '7-mar-2010' 200.00



create table my_test (
id number(10),
start_date date,
end_date date,
amount number(10,2)
);


select * from my_test

insert into my_test values (1, '3-mar-2010', '7-mar-2010', 1000);
insert into my_test values (2, '10-mar-2010', '19-mar-2010', 2000);
insert into my_test values (3, '20-mar-2010', '21-mar-2010', 5000);



Thanks in advance.
This post has been answered by Frank Kulash on Apr 26 2010
Jump to Answer

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 25 2010
Added on Apr 26 2010
5 comments
3,220 views