我有一個SQL查詢,投2個日期,並檢查它們是否相等。但即使日期是平等的,我沒有得到結果。函數獲得兩個日期之間的平日數除外假期
create or replace
FUNCTION getWorkingDays(
DATE_ONE DATE,
DATE_TWO DATE)
RETURN NUMBER
IS
DAY_COUNT NUMBER := 0;
START_DATE DATE;
END_DATE DATE;
HOL_COUNT NUMBER := 0;
BEGIN
IF(DATE_ONE IS NOT NULL AND DATE_TWO IS NOT NULL) THEN
IF DATE_ONE < DATE_TWO THEN
START_DATE := DATE_ONE;
END_DATE := DATE_TWO;
ELSE
START_DATE := DATE_TWO;
END_DATE := DATE_ONE;
END IF;
WHILE START_DATE < END_DATE
LOOP
IF TO_CHAR(START_DATE,'DY') NOT IN ('SAT','SUN') THEN
DAY_COUNT := DAY_COUNT + 1;
END IF;
SELECT count(*) INTO HOL_COUNT
FROM ATL_JOB_HOLIDAY jh
JOIN ATL_MASTER_JOB mj
ON MJ.MASTER_JOB_ID = JH.MASTER_JOB_ID
WHERE TRUNC(HOLIDAY_DATE) = START_DATE;
IF(HOL_COUNT >0) THEN
DAY_COUNT := DAY_COUNT + 1;
Dbms_Output.put_line('Holiday333 :- IS A HOLIDAY');
END IF;
START_DATE := START_DATE + 1;
END LOOP;
END IF;
RETURN DAY_COUNT;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END getWorkingDays;'
什麼是您的DBMS? 「在SQL中」?什麼SQL?甲骨文? PostgreSQL的? –
ANSI SQL不能將'16 -APR-11'識別爲日期。你使用哪個dbms? – jarlh