Oracle:如何减去两个日期并获得结果的分钟数

Oracle : how to subtract two dates and get minutes of the result(Oracle:如何减去两个日期并获得结果的分钟数)
本文介绍了Oracle:如何减去两个日期并获得结果的分钟数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了这个函数来获取某个日期的分钟数,但我无法获取两个日期之间的分钟数,如何获取?

I wrote this function to get minutes from a date, but I cannot get minutes between two dates, How to get that ?

FUNCTION get_minute(p_date DATE)
RETURN NUMBER
IS
BEGIN
    IF p_date IS NOT NULL THEN
        return  EXTRACT(MINUTE FROM TO_TIMESTAMP(to_char(p_date,'DD-MON-YYYY HH:MI:SS'),'DD-MON-YYYY HH24:MI:SS'));
    ELSE
        RETURN 0;
    END IF;
END get_minute;

推荐答案

当你在 Oracle 中减去两个日期时,你会得到两个值之间的天数.所以你只需要在几分钟内乘以得到结果:

When you subtract two dates in Oracle, you get the number of days between the two values. So you just have to multiply to get the result in minutes instead:

SELECT (date2 - date1) * 24 * 60 AS minutesBetween
FROM ...

这篇关于Oracle:如何减去两个日期并获得结果的分钟数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)
SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to group by continuous records in SQL(如何在SQL中按连续记录分组)