[英]Oracle SQL Convert number field to hh:mm
I have looked at other similar articles but non are giving me the correct outcome.我看过其他类似的文章,但没有给我正确的结果。 I have a field called 'Duration' with numbers in minutes stored as an integer. I need to convert that to hh:mm so:
我有一个名为“持续时间”的字段,其中以分钟为单位的数字存储为 integer。我需要将其转换为 hh:mm,因此:
Duration![]() |
hh:mm![]() |
---|---|
120 ![]() |
02:00 ![]() |
545 ![]() |
09:08 ![]() |
3600 ![]() |
60:00 ![]() |
I've experimented with to_char, to_date, and a few others but not getting anywhere.我已经尝试过 to_char、to_date 和其他几个但没有取得任何进展。
You can try using:您可以尝试使用:
NUMTODSINTERVAL
function, that will transform your integer to seconds NUMTODSINTERVAL
function,这会将您的 integer 转换为秒TO_CHAR
function, that will format your seconds to your required time frame TO_CHAR
function,这会将您的秒数格式化为您需要的时间范围SELECT Duration,
TO_CHAR(TIME'0:0:0'+NUMTODSINTERVAL(Duration,'second'),'hh24:mi:ss')
FROM tab
Divide the duration (seconds) by 60. The quotient is the minutes, the remainder is the seconds.将持续时间(秒)除以 60。商是分钟,余数是秒。
select
duration,
to_char(trunc(duration / 60), 'FM00') ||
':' ||
to_char(mod(duration, 60), 'FM00') as time
from mytable;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.