convert minutes to hh/mi/ss format in oracle query -


i want know query converts minutes format of hh/mi/ss in oracle.i 've seen lot of same questions many forums nothing helped me exact result.

the query used -select to_char(to_date(mod(100,60),'mi'),'hh/mi/ss') dual; don't know how hour value.because mod function returns remainder don't know how take quotient part , substitute hour field.

i suppose there 2 ways of storing "minutes" in oracle database - can either store them in field datatype interval day second, or can store them in number. simplest case handle interval - in case, to_char function converts value string of form sdd hh:mm:ss.ffffff, 's' sign ('+' or '-' intervals can positive or negative), dd = days, hh= hours, 'mm' = minutes, 'ss' = seconds, , 'ffffff' = fractions; thus, hh:mi:ss need use substr function, in

substr(to_char(i_val), 5, 8) 

where i_val interval day second value.

if value converted in numeric field gets bit messy have compute individual field values, subtract previous fields part of getting next field. however, since value stored in minutes instead of seconds it's not particularly difficult:

create table tst (n_val  number,                   i_val  interval day second);  insert tst(n_val, i_val) values (666, interval '666' minute);  select n_val,         trunc(n_val/60) hours,        n_val-(trunc(n_val/60) * 60) minutes,        0 seconds,        to_char(i_val),        substr(to_char(i_val), 5, 8) hms_from_interval   tst; 

sqlfiddle here

best of luck.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -