我正在pl-SQL环境中工作,但访问权限非常有限。
对于具有2个flds的表:
我要计算工作日/工作日
(例如:endPeriod-startPeriod -nonWorkingDays)
Utsav的回答很有帮助:
Want a SQL to get days between 2 date and exclude Saturday and Sunday in Oracle,
但是我不能用表中的动态日期替换硬编码日期。
以下基于Utsav答案的查询返回错误消息:“无效标识符”
SELECT t,startPeriod,t.endPeriod,
(
With test_data as (select t.startPeriod as start_date,t.endPeriod as end_date from dual ),
all_dates as (select td.start_date + level-1
as week_day from test_data td connect by
td.start_date + level-1< td.end_date)
select count(*) from all_dates where
to_char(week_day,'dy', 'nls_date_language-american') not in ('sun','sat') and week_day not in ('01jan2019','02feb2019')
) as workingDaysField
FROM dbo.TBL t