需要在Oracle中查找下一个和上一个工作日 [英] Need to find next and previous working day in oracle

查看:1246
本文介绍了需要在Oracle中查找下一个和上一个工作日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询有点像这样:

select 1 from dual where :p1_task_date in (sysdate,sysdate+1,sysdate-1) and :p1_task_id is not null

这工作正常,但我想获得下一个/上一个工作日(下一个/上一个工作日),而不是sysdate + 1和sysdate-1.我尝试过类似的事情:

This works fine, but I wanted to get next/previous working days (next/previous week days) instead of sysdate+1 and sysdate-1. I tried something like:

select next_day(sysdate, to_char(sysdate+1,'DAY')) from dual`

但无法继续进行此操作:(

but cannot proceed with this :(

请帮助!!!

推荐答案

@Tawman的答案会起作用,但出于可读性考虑,我更喜欢这种方法:

@Tawman's answer will work, but I prefer this method for readability:

select sysdate as current_date,
       case when to_char(sysdate,'D') in (1,6,7)
            then next_day(sysdate,'Monday')
            else sysdate+1 end as next_weekday,
       case when to_char(sysdate,'D') in (1,2,7)
            then next_day(sysdate-7,'Friday')
            else sysdate-1 end as prev_weekday
from dual

正如其他人所说,这仅在排除周末而不是假期时起作用.

As everyone else has stated, this will only work to exclude weekends, not holidays.

这篇关于需要在Oracle中查找下一个和上一个工作日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆