【发布时间】:2019-08-06 09:51:10
【问题描述】:
F 是一个计算两个日期之间的工作日数的函数(使用格式 to_date(a, 'DD/MM/YYYY') [NLS_DATE_LANGUAGE = "FRENCH"]。
它存储在包P中。
a 是期间的开始日期,b 是结束日期。
当我使用 SQL developer 运行函数时,即右键单击包p,执行,选择f 函数并填写参数:
if a = to_date('02/08/2019', 'DD/MM/YYYY') and b = to_date('12/08/2019', 'DD/MM/YYYY'))
我得到的天数 = 7,这是正确的结果。
但是当我在 SQL 中运行它时:
select p.f('02/08/2019','12/08/2019') from DUAL
我得到的天数 = 8,这个结果显然是错误的。
我无法理解这两个进程如何返回两个不同的值,因为调用了相同的F 函数,并且参数完全相同。
我一直注意日期格式,仍然两种调用f的方式不会返回相同的结果。
仅供参考,这是这个函数的内容(对不起,cariable是用法语表示的)
FUNCTION getjoursouvres
(
i_debut IN DATE,
i_fin IN DATE
)
RETURN NUMBER IS o_result NUMBER;
v_jour date;
v_nbjours NUMBER;
v_testferie number;
v_testweekend number;
v_testglobal number;
-- This cursor browses all dates between i_debut and i_fin (included)
cursor cx is
select to_date(i_debut, 'DD/MM/YYYY') + rownum -1 dt
from dual
connect by level <= to_date(i_fin, 'DD/MM/YYYY') - to_date(i_debut, 'DD/MM/YYYY') + 1;
BEGIN
open cx;
v_nbjours := 0;
loop
-- Browses all the days in the interval (begining and end included)
fetch cx into v_jour;
exit when cx%NOTFOUND;
-- testferie return 1 if the day is NOT a holiday, 0 if it is (so not be be added)
v_testferie := testferie(v_jour);
-- testweekend return 1 if the day is a weekday, 0 if it is on weekend (so not be be
v_testweekend := testweekend(v_jour);
--
v_testglobal := v_testferie + v_testweekend;
-- If v_testglobal = 2 then the day is neither weekend nor holiday. Therefore it is aded to the sum of days
if v_test = 2 then
v_nbjours := v_nbjours + 1;
end if;
end loop;
o_result := v_nbjours;
close cx;
return o_result;
END;
【问题讨论】:
-
请您编辑您的问题以包含您的函数
f的内容。 -
select f.p(a,b) from DUAL- 在这种情况下,a和b是什么?
标签: oracle plsql oracle-sqldeveloper