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!

"Ceil" on an interval?

John_KSep 28 2017 — edited Sep 29 2017

I have a table which is storing a number of hours as a number (this I cannot change). This can be any decimal number. I am converting that into hours and minutes for display purposes, however I would like to round UP the minutes part.

select extract (hour from numtodsinterval (8.333, 'HOUR')) hours,

       extract (minute from numtodsinterval (8.333, 'HOUR')) mins,

       numtodsinterval (8.333, 'HOUR') intv

  from dual;

hoursminsintv
819+00 08:19:58.800000

What I want to do is round UP the number of minutes in the interval - so I have 8 hours, 19 minutes, 58 seconds (8.333 hours) - I want to display that as 8 hours 20 minutes.

I've tried the obvious of using ceil but that can't be applied to an interval.

I know I can do the maths manually :

with x as

(select 8.333 i from dual)

Select floor(i) hours, round(mod(i,1) * 60) mins From x;

but I wanted to check this couldn't be done with intervals (more from an academic perspective) before going down that route. I also prefer the Interval syntax as I find it more obvious what is going on from a readability point of view.

This post has been answered by mathguy on Sep 28 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 27 2017
Added on Sep 28 2017
16 comments
512 views