Oracle Date Subtraction(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 日期减法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Oracle 日期减法
基础教程推荐
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
