def 基準日 = to_date('2006/07/14','YYYY/MM/DD')
def 差分日数 = 2
with hoge as(
select to_date('2006/07/10', 'yyyy/mm/dd') as 日付,0 as 休日フラグ from dual
union select to_date('2006/07/11','yyyy/mm/dd'),0 from dual
union select to_date('2006/07/12','yyyy/mm/dd'),0 from dual
union select to_date('2006/07/13','yyyy/mm/dd'),0 from dual
union select to_date('2006/07/14','yyyy/mm/dd'),0 from dual
union select to_date('2006/07/15','yyyy/mm/dd'),1 from dual
union select to_date('2006/07/16','yyyy/mm/dd'),1 from dual
union select to_date('2006/07/17','yyyy/mm/dd'),1 from dual
union select to_date('2006/07/18','yyyy/mm/dd'),0 from dual
union select to_date('2006/07/19','yyyy/mm/dd'),0 from dual)
select 取得日
from (select 日付,
case when &差分日数 > 0
then Lead(日付,abs(&差分日数)) over(order by 日付)
else Lag(日付,abs(&差分日数)) over(order by 日付) end as 取得日
from hoge
where 休日フラグ = 0 or 日付 = &基準日)
where 日付 = &基準日;
def 差分日数 = -1
/
def 基準日 = to_date('2006/07/17','YYYY/MM/DD')
def 差分日数 = 2
/
def 差分日数 = -1
/