A personal blog of Christopher Wigginton; a nerd by nature, programming polyglot, cooking enthusiast and fermentation practitioner.
Monday, August 5, 2019
Oracle: Obtaining a date for a given business day in a month.
Oracle SQL to get the date for a given business day in a passed in month, sysdate used for example.
With a as(
,to_number(to_char(trunc(sysdate,'MM')-1+level,'D')) as weekday
,rownum as business_day
where to_char(trunc(sysdate,'MM')-1+level,'D') notin (1,7)
-- add in a check for a holday calendar here
CONNECT BYLEVELbetween1andEXTRACT(dayfrom last_day(sysdate))
select a.dayfrom a where business_day =5