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 日期减法


基础教程推荐
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01