网上搜的sql语句,感觉很有用,记下啦
-- 求一个给定日期距今天(当前)的工作日数!
CREATE OR REPLACE FUNCTION workdays_today(i_date IN VARCHAR2) -- 输入日期的参数,用varchar2类型,其日期格式为:yyyy-mm-dd
RETURN NUMBER
IS
v_day NUMBER(18,0);
BEGIN
SELECT COUNT(1) INTO v_day FROM (
SELECT to_date(i_date,'YYYYMMDD') + level - 1 as cdays FROM dual
CONNECT BY level <=
(SYSDATE - to_date(i_date,'YYYY-MM-DD') +1 )) T
WHERE to_char(cdays,'D') <> 1
AND to_char(cdays,'D') <> 7;
RETURN v_day;
END;
SELECT workdays_today('20110101') FROM DUAL;
------------------------------------------------------------------
另 这有一问题:
从当前日期算起得到指定天数(不如5天或三天)前的日期。
这条语句该如何写?
请各位大侠多多指教...