當系統執行到本處sql時,將本年度(或指定年份)一全年365天對應的是否爲工做日狀況數據插入到指定表中(如:0表示工做日,1表示雙休日,法定節假日手動調整)。
create table WORK_DAYS ( work_days_id NUMBER not null, one_day DATE, type NUMBER, created_on DATE, created_by NUMBER, updated_on DATE, updated_by NUMBER ) tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited );
create sequence seq_work_days increment by 1 start with 1 nomaxvalue nocycle nocache;
insert into work_days(work_days_id,one_day,type) with x0 as (select to_date('2016-01-01','yyyy-MM-dd') as 年初,to_date('2016-12-31','yyyy-MM-dd') as 年底 from dual ), x1 as (select 年初 + level - 1 as 日期 from x0 connect by level <= (年底 - 年初) + 1), x2 as (select 日期,to_number(to_char(日期, 'd')) 周幾 from x1) select seq_work_days.nextval,日期,(case when 周幾=1 or 周幾=7 then then 1 else 0 end) as 工做日標誌 from x2
【Select to_char(sysdate,'d') from dual取當前時間是一週的第幾天,從星期天開始,週六結束。即1爲星期日,以此類推。】sql
select t.*, t.rowid from WORK_DAYS t