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!

SQL Query to split a day into rows per hour

Don07Feb 19 2020 — edited Feb 20 2020

Hello There,

I have a requirement to split a day into 1 hour wise (which includes hour, minutes and seconds) by each row.

The user will pass as a parameter P_DAY (Format: DD-MMM-YYYY), and based on input parameter the sql query should generate the rows as in the output

Eg. P_DAY = 19-Feb-2020

Output:

    

DayStart TimeEnd TimeStart HourEnd Hour
19-Feb-202019 Feb 2020 00:00:0019 Feb 2020 01:00:0000:00:0001:00:00
19-Feb-202019 Feb 2020 01:00:0019 Feb 2020 02:00:0001:00:0002:00:00
19-Feb-202019 Feb 2020 02:00:0019 Feb 2020 03:00:0002:00:0003:00:00
….…..…..…..…..
….…..…..…..
19-Feb-202019 Feb 2020 22:00:0019 Feb 2020 23:00:0022:00:0023:00:00
19-Feb-202019 Feb 2020 23:00:0019 Feb 2020 23:59:5923:00:0023:59:59

Could you please advice?

Look forward to hearing from you.

Regards,

Don

This post has been answered by BluShadow on Feb 19 2020
Jump to Answer
Comments
Post Details
Added on Feb 19 2020
8 comments
2,311 views