Using LIKE in an Oracle IN clause

前端 未结 9 1545
情深已故
情深已故 2020-12-06 09:49

I know I can write a query that will return all rows that contain any number of values in a given column, like so:

Select * from tbl where my_col in (val1, v         


        
9条回答
  •  [愿得一人]
    2020-12-06 10:14

    Just to add on @Lukas Eder answer.

    An improvement to avoid creating tables and inserting values (we could use select from dual and unpivot to achieve the same result "on the fly"):

    with all_likes as  
    (select * from 
        (select '%val1%' like_1, '%val2%' like_2, '%val3%' like_3, '%val4%' as like_4, '%val5%' as like_5 from dual)
        unpivot (
         united_columns for subquery_column in ("LIKE_1", "LIKE_2", "LIKE_3", "LIKE_4", "LIKE_5"))
      )
        select * from tbl
        where exists (select 1 from all_likes where tbl.my_col like all_likes.united_columns)
    

提交回复
热议问题