当前位置:网站首页>Oracle 日历表详解(含节假日)
Oracle 日历表详解(含节假日)
2022-08-03 05:22:00 【鱼丸丶粗面】
1 概述
2 示例
2.1 判断双休日
-- 2022 年全年: 364 天
select date '2023-01-01' - date '2022-01-01' - 1 天数
from dual;
-- 系统默认 和 日常使用习惯
select to_char(sysdate, 'D') 默认天,
to_char(sysdate - 1, 'D') 习惯天
from dual;
-- 核心逻辑
select date '2022-01-01' + rownum - 1 日期,
to_char(date '2022-01-01' + rownum - 2, 'D') 星期几
from dual
connect by rownum <= 364;
2.2 判断节假日
with t_date_base as
( -- 一般日
select date '2022-01-01' + rownum - 1 日期,
to_char(date '2022-01-01' + rownum - 2, 'D') 星期几
from dual
connect by rownum <= 364),
t_jjr as
( -- 节假日
select date '2022-01-29' 日期, '补班' 日期类型 from dual
union all
select date '2022-01-30' 日期, '补班' 日期类型 from dual
union all
select date '2022-01-31' 日期, '除夕' 日期类型 from dual
union all
select date '2022-02-01' 日期, '春节' 日期类型 from dual)
select t1.日期,
t1.星期几,
(case -- 注意顺序
when t2.日期 is not null and t2.日期类型 <> '补班' then
'节假日'
when t2.日期 is not null and t2.日期类型 = '补班' then
'工作日'
when t1.星期几 in ('6', '7') then
'节假日' -- 双休日
else
'工作日'
end) 日期类型
from t_date_base t1,
t_jjr t2
where t2.日期(+) = t1.日期
order by t1.日期;
查询结果:(部分)
日期 星期几 日期类型
2022/1/24 1 工作日
2022/1/25 2 工作日
2022/1/26 3 工作日
2022/1/27 4 工作日
2022/1/28 5 工作日
2022/1/29 6 工作日
2022/1/30 7 工作日
2022/1/31 1 节假日
2022/2/1 2 节假日
边栏推荐
猜你喜欢
随机推荐
令人愉快的 Nuxt3 教程 (二): 快速轻松地搭建博客
7.15(6)
Invalid signature file digest for Manifest main attributes解决方法
小码农的第一篇博客
Makefile 遍历子目录模板
初识C语言
中国石油行业并购重组趋势与投资战略规划建议报告2022~2028年
浏览器中的 preview 和 response 的值不一致
npm run dev/serve 时报错
MySQL 索引详解和什么时候创建索引什么时候不适用索引
中国水煤浆行业“十四五”规划与运营模式分析报告2022~2028年
关于如何向FastAPI的依赖函数添加参数
7.21[日常]
Haproxy服务监控
【DC-5靶场渗透】
The ` monorepo ` ` hoist ` mechanism lead to the change of the loading configuration file path
跨域错误的原因及处理方法
中国食品微生物检测行业深度监测及投资战略规划建议报告2022~2028年
【DC-2靶场渗透】
[Rebound shell and privilege escalation]









