Oracle
 sql >> Base de données >  >> RDS >> Oracle

Oracle SI Existe ALORS, SINON

Calculez d'abord la condition, puis appliquez-la au dernier SELECT en utilisant CASE . Quelque chose comme ça :

with temp (validexists) as
  (select count(column1)
   from table1
   where column1 in ('Yes') 
      and column2 not like '%Yes%'
  )
  select *
    into l_row
    from table1
    where column1 in ('Yes')
      and column2 in (select column2
                      from table1 cross join temp
                      where column1 in ('Yes')
                        and column2 not like case when validexists = 0 then '%Yes%'
                                                  else                      '%No%'
                                             end
                     );