我该怎么创建一个节假日表
时间: 2024-04-25 22:23:35 浏览: 66
要创建一个节假日表,你可以使用以下SQL语句:
```
with x0 as (
select to_date('2018-01-01','yyyy-MM-dd') as 年初,
to_date('2018-12-31','yyyy-MM-dd') as 年末
from dual
),
holiday_data as (
select wk_day,
case
when wk_day in ('20210101', '20210102', '20210103', '20210211', '20210212', '20210213', '20210214', '20210215', '20210216', '20210217', '20210403', '20210404', '20210405', '20210501', '20210502', '20210503', '20210504', '20210505', '20210612', '20210613', '20210614', '20210919', '20210920', '20210921', '20211001', '20211002', '20211003', '20211004', '20211005', '20211006', '20211007') then '2'
when wk_day in ('20210207', '20210220', '20210425', '20210508', '20210918', '20210926', '20211009') then '0'
else '1'
end as day_typ
from (
select to_char(to_date('20210101', 'yyyyMMdd') + rownum - 1, 'yyyymmdd') as wk_day
from dual
connect by rownum <= trunc(to_date('20211231', 'yyyyMMdd') - to_date('20210101', 'yyyyMMdd')) + 1
)
)
insert into t_pub_wkday (wk_day, day_typ)
select wk_day, day_typ
from holiday_data;
```
这个SQL语句使用了两个子查询。第一个子查询(x0)定义了年初和年末的日期。第二个子查询(holiday_data)生成了所有日期和对应的day_typ(0表示工作日,1表示休息日,2表示节假日)。最后,将结果插入到t_pub_wkday表中。
请注意,你需要根据你的具体需求和数据库表结构进行适当的修改。
#### 引用[.reference_title]
- *1* [oracle 产生节假日表](https://blog.csdn.net/weixin_39901571/article/details/116291922)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Oracle 数据库生成2021年节假日表SQL](https://blog.csdn.net/xiehuaxing/article/details/111317809)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文