說明:
將指定年份一整年365天對應的是否為工作日情況數據插入到指定表中 work_days(TYPE:0表示工作日,1表示雙休日,法定節假日手動調整)
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 WEBSITE
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
2.oracle表主鍵自增序列:
create sequence seq_work_days
increment by 1
start with 1
nomaxvalue
nocycle
nocache;
3.查出結果並插入至指定表:
insert into work_days(work_days_id,one_day,type)
with x0 as (select to_date('2018-01-01','yyyy-MM-dd') as 年初,to_date('2018-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
WORK_DAYS 指定年份數據已經生成
下面是根據具體的業務需求擴展解析到具體的數據可自參考:
begin
for rec in (select * from work_days) loop
insert into t_sys_holiday
(id, year, month, day, type, modperson, modtime)
values
(to_char(sysdate, 'yyyymmddhh24miss') || rec.work_days_id,
substr(to_char(rec.one_day, 'yyyymmddhh24miss'), 0, 4),
substr(to_char(rec.one_day, 'yyyymmddhh24miss'), 5, 2),
substr(to_char(rec.one_day, 'yyyymmddhh24miss'), 7, 2),
rec.type,
'zh',
sysdate);
end loop;
end;