Oracle 日期减法 [英] Oracle Date Subtraction

查看:49
本文介绍了Oracle 日期减法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何编写一个表达式,让我以天、小时、分钟、秒等为单位给出两个日期之间的差异?默认情况下,在 oracle 中减去两个日期以十进制形式返回天数.

How would i write an expression that gives me the difference between two dates in days, hours, minutes, seconds, etc? By default subtracting two dates in oracle returns days as a decmial.

推荐答案

那个小数点是提供的两个日期之间相差的天数.您可以做一些数学运算,将其转换为天、小时、分钟、秒等.

That decimal is the number of days difference between the two dates provided. You can do a little math to convert that to days, hours, minutes, seconds, etc.

编辑:我知道你在找什么.我确定有更简单的方法,但我可能会这样完成:

EDIT: I see what you're looking for. I'm sure there's an easier way, but I would probably accomplish it thusly:

select trunc(5.3574585) days, 
       trunc(mod((5.3574585) * 24, 24)) hours, 
       trunc(mod((5.3574585) * 24 * 60, 60)) minutes, 
       trunc(mod((5.3574585) * 24 * 60 * 60, 60)) seconds 
  from dual;

...其中 5.3574585 是减法返回的天数...

...where 5.3574585 is the number of days returned by the subtraction...

注意:这并没有经过真正的测试,这是我的想法.

这篇关于Oracle 日期减法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆