sql >> Base de Datos >  >> RDS >> Oracle

¿Cómo lidiar con el límite de anidamiento profundo de 1 nivel en Oracle?

Mi enfoque sería generar una cantidad fija de fechas a partir de sysdate -1 descendente y luego trabajar en ellas. En el siguiente fragmento, elegí 100. Una vez que obtuviste la fecha correcta, solo utilízala para filtrar en la tabla 1.

select dates 
  from (
  select rownum as rn, 
         dates 
    from (
    select x.dates, 
           nvl2(h.holiday_from,'T','F') as hd, 
           decode (to_char(x.dates,'D')-1,6,'T',7,'T','F') as WE 
      from (
      select trunc(sysdate) - rownum as dates
        from dual d
     connect By rownum <= 100 -- change this number if you plan on having long holidays
           ) x 
    left outer join holidays h
      on x.dates between h.holiday_fromand h.holiday_to
         )
   where hd = 'F' and WE = 'F' -- exclude holidays and weekends
       )
 where rn = 14; -- return the 14th working day from now