为什么我的PL / SQL持续时间功能不能正常工作?在下面的查询中,我以与下面函数相同的方式手动计算'hh:mm'。但是,我得到了不同的结果。
致电查询:
WITH durdays AS (SELECT SYSDATE - (SYSDATE - (95 / 1440)) AS durdays FROM DUAL)
SELECT TRUNC (24 * durdays) AS durhrs,
MOD (TRUNC (durdays * 1440), 60) AS durmin,
steven.duration (SYSDATE - (95 / 1400), SYSDATE) duration
FROM durdays
输出:
durhrs: 1
durmin: 35
duration: '1:38'
功能代码:
CREATE OR REPLACE FUNCTION steven.duration (d1 IN DATE, d2 IN DATE)
RETURN VARCHAR2 IS
tmpvar VARCHAR2 (30);
durdays NUMBER (20,10); -- Days between two DATEs
durhrs BINARY_INTEGER; -- Completed hours
durmin BINARY_INTEGER; -- Completed minutes
BEGIN
durdays := d2-d1;
durhrs := TRUNC(24 * durdays);
durmin := MOD (TRUNC(durdays * 1440), 60);
tmpvar := durhrs || ':' || durmin;
RETURN tmpvar;
END duration;
/
答案 0 :(得分:5)
我想你可能会有一个小错字:
WITH durdays AS (SELECT SYSDATE - (SYSDATE - (95 / 1440)) AS durdays FROM DUAL)
^^^^
SELECT TRUNC (24 * durdays) AS durhrs,
MOD (TRUNC (durdays * 1440), 60) AS durmin,
lims_sys.duration (SYSDATE - (95 / 1400), SYSDATE) duration
^^^^
一旦修复它就可以了:
SQL> WITH durdays AS (SELECT SYSDATE - (SYSDATE - (95 / 1440)) AS durdays FROM DUAL)
2 SELECT TRUNC (24 * durdays) AS durhrs,
3 MOD (TRUNC (durdays * 1440), 60) AS durmin,
4 duration (SYSDATE - (95 / 1440), SYSDATE) duration
5 FROM durdays
6 ;
DURHRS DURMIN DURATION
---------- ---------- ----------------
1 34 1:34
答案 1 :(得分:-1)
sql>set time on
然后你会收到如下提示:
20:24:35 sql> select count(*) from v$session; count(*) ----------- 78 20:24:50 sql>
现在你可以知道查询持续时间是15秒