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!

Split single row into multiple rows containing time periods

Dan Scott GuestFeb 11 2010 — edited Jan 27 2011
Hi,

I have a table with rows like this:

id, intime, outtime
1, 2010-01-01 00:10, 2010-01-3 20:00

I would like to split this row into multiple rows, 1 for each 24hr period in the record.

i.e. The above should translate into:
id, starttime, endtime, period
1, 2010-01-01 00:10, 2010-01-02 00:10, 1
1, 2010-01-02 00:10, 2010-01-03 00:10, 2
1, 2010-01-03 00:10, 2010-01-03 20:00, 3

The first starttime should be the intime and the last endtime should be the outtime.

Is there a way to do this without hard-coding the 24hr periods?

Thanks,

Dan Scott
http://danieljamesscott.org
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2011
Added on Feb 11 2010
20 comments
7,472 views