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 日期减法
基础教程推荐
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
