获得一个日期在当周是否有节日并返回日期
函数: CREATE OR REPLACE FUNCTION FUN_GET_HOLIDAY (TEMDATE VARCHAR2) RETURN VARCHAR2 IS holiday_ALL VARCHAR2 (200); CURSOR c_date IS SELECT RQ FROM CHINESECALENDAR WHERE TO_DATE (RQ, 'YYYY-MM-DD') --查询输入日期所在日期的这周的起止日期-- BETWEEN TRUNC ( TO_DATE (TEMDATE,'yyyy-mm-dd'),'iw') AND TRUNC (TO_DATE (TEMDATE,'yyyy-mm-dd'),'iw') + 6 AND JR IS NOT NULL; c_row c_date%ROWTYPE; BEGIN holiday_ALL := ''; OPEN c_date; LOOP FETCH c_date INTO c_row; EXIT WHEN c_date%NOTFOUND; holiday_ALL := holiday_ALL || ',' || c_row.rq; END LOOP; CLOSE c_date; RETURN holiday_ALL; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN -1; END FUN_GET_HOLIDAY; / --调用方法-- SELECT FUN_GET_HOLIDAY('2015-08-05') FROM dual; --执行结果-- FUN_GET_HOLIDAY('2015-08-05') ,2015-08-08,2015-08-09
获得一个日期的这周的开始日期和结束日期
SELECT RQ FROM CHINESECALENDAR WHERE TO_DATE (RQ, 'YYYY-MM-DD') BETWEEN trunc(date'2015-08-05','iw') AND trunc(date'2015-08-05','iw')+6; --执行结果-- 2015-08-03 2015-08-04 2015-08-05 2015-08-06 2015-08-07 2015-08-08 2015-08-09