Using the “IN” clause with a comma delimited string from the output of a replace() function in Oracle SQL

前端 未结 5 916
逝去的感伤
逝去的感伤 2020-11-29 09:45

I have an comma delimited string which I want to use in an \"IN\" clause of the statement. eg: 100,101,102

Since In and \"IN\" clause I have to quote the individial

5条回答
  •  自闭症患者
    2020-11-29 10:24

    As the comma-separated values contain only digits, why not try something as simple as using:

    INSTR(','||my_csv_list_of_values||',', ','||my_search_value||',') <> 0
    

    See this example:

    -- some test data
    with employee as (
      select 101 as employee_number from dual
      union select 200 from dual
      union select 10 from dual
      union select 102 from dual)
    
    -- the actual query
    select * from employee
      where INSTR(','||'101,102,103,104'||',', ','||employee_number||',') <> 0;
    --                 ^^^^^^^^^^^^^^^^^
    --                   your CSV data
    

    Producing:

    EMPLOYEE_NUMBER
    101
    102
    

提交回复
热议问题