This works, but Oracle will throw an error if you try to make an interval
expression that’s longer than 200 characters. So you could make a function
out of it.
select case
when --the july date this year has passed
((sysdate - next_day(to_date( ‘07/07/’ || to_char(sysdate, ‘yyyy’ ),
‘dd//mm/yyyy’ ), ‘SUNDAY’ )) > 0 ) then
– return the january date for next year
next_day(to_date( ‘07/01/’ || to_char(to_number(to_char(sysdate, ‘yyyy’ )) +
1 ), ‘dd//mm/yyyy’ ), ‘SUNDAY’ )
when --the january date this year has passed
((sysdate - next_day(to_date( ‘07/01/’ || to_char(sysdate, ‘yyyy’ ),
‘dd//mm/yyyy’ ), ‘SUNDAY’ )) > 0 ) then
– return the july date for this year
next_day(to_date( ‘07/07/’ || to_char(sysdate, ‘yyyy’ ), ‘dd//mm/yyyy’ ),
‘SUNDAY’ )
else
– return the january date for this year
next_day(to_date( ‘07/01/’ || to_char(sysdate, ‘yyyy’ ), ‘dd//mm/yyyy’ ),
‘SUNDAY’ )
end next_second_sun_jan_or_july
from dual