Comparing list of values against table

后端 未结 3 726
梦谈多话
梦谈多话 2021-01-15 09:47

I tried to find solution for this problem for some time but without success so any help would be much appreciated. List of IDs needs to be compared against a table and find

3条回答
  •  孤独总比滥情好
    2021-01-15 10:13

    One way of tackling this is to dynamically create a common table expression that can then be included in the query. The final synatx you'd be aiming for is:

    with list_of_values as (
      select 100 val from dual union all
      select 200 val from dual union all
      select 300 val from dual union all
      ...)
    select
      lov.val,
      ...
    from
      list_of_values lov left outer join 
      other_data     t   on (lov.val = t.val)
    

    It's not very elegant, particularly for large sets of values, but compatibility with a database on which you might have few privileges is very good.

提交回复
热议问题