Using LIKE in an Oracle IN clause

前端 未结 9 1556
情深已故
情深已故 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:16

    I prefer this

    WHERE CASE WHEN my_col LIKE '%val1%' THEN 1    
               WHEN my_col LIKE '%val2%' THEN 1
               WHEN my_col LIKE '%val3%' THEN 1
               ELSE 0
               END = 1
    

    I'm not saying it's optimal but it works and it's easily understood. Most of my queries are adhoc used once so performance is generally not an issue for me.

提交回复
热议问题