zoukankan      html  css  js  c++  java
  • oracle 产生节假日表

    说明:

    将指定年份一整年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;

  • 相关阅读:
    20160421
    20160420笔记
    第一个随笔
    搬家
    OO第十五次作业
    OO第三次博客作业
    OO5-7次作业总结
    从入门到不放弃——OO第一次作业总结
    第八次团队作业——系统设计和任务分配
    第七次作业-团队选题报告和需求规格说明书
  • 原文地址:https://www.cnblogs.com/auldlangsynezh/p/8478029.html
Copyright © 2011-2022 走看看