Oralce資料庫計算工作日(處理假期及加班)

2021-10-09 21:35:47 字數 1428 閱讀 1860

字段設計:日期(bdate)、是否假期(hflag)、假期名稱(name)

維護假期資訊表,請求介面、手動維護都可以。主要是需標識出一年內的假期以及加班日,資料量一般就30至40條。hflag為true代表假期,false代表加班日。

2、直接copy**:

--建立檢視:view_workdays

create or replace view view_workdays as

select cast(bdate as nvarchar2(10)) bdate

from(

select to_char(trunc(sysdate, 'yyyy') + rownum - 1,'yyyy-mm-dd') bdate

from dual

connect by rownum <= add_months(trunc(sysdate, 'yyyy'), 12) - trunc(sysdate, 'yyyy')

)--holiday_of_china為第一步驟建立的維護表,用於儲存特殊日期

--排除假期及週末(hflag判斷是否為假期)

where to_char(to_date(bdate,'yyyy-mm-dd'),'d') not in (1,7)

and bdate not in (

select bdate from holiday_of_china where hflag= 'true'

) union all

--增加週六週末調整為上班的時間

select bdate

from holiday_of_china

where hflag= 'false'

order by bdate desc;

3、使用檢視:

--查詢整年的工作日

select bdate

from view_workdays

效果(2023年國慶前後工作日):

2020-10-14

2020-10-30

2020-10-13

2020-10-29

2020-10-12

2020-10-28

2020-10-10

2020-10-27

2020-10-09

2020-10-26

2020-09-30

2020-10-23

2020-09-29

2020-10-22

2020-09-28

2020-10-21

2020-09-27

2020-10-20

2020-09-25

2020-10-19

2020-09-24

2020-10-16

2020-09-23

2020-10-15

計算工作日

vb vba中計算工作日 僅剔除星期 六 日 的函式。function getworkdaycount startday as date,endday as date as integer dim nums as integer,numy as integer dim weekdaynumy 7,6...

動態計算工作日

由table來設定是否為工作日,如果為節假日則設定為非工作日,即talbe會設定每天是否為工作日 帶入的日期必須為工作日。alter function dbo fn workdayadd date datetime days int returns datetime nvarchar 100 asb...

轉貼 工作日的計算

using system using system.data using system.configuration using system.collections using system.web using system.web.security using system.web.ui usin...