简体   繁体   中英

SQL-Statement to use predefined values list as an SQL-table

I have a list of ids. eg (1, 2, 10). Is it possible to use that list as a table in Oracle ?

I mean something like that:

select * from (1, 2, 10) as x, some_table
where x not in some_table.value

You can use with construction

with x as (
  select 1 as v from dual
  union all
  select 2 from dual
  union all
  select 10 from dual
)

select *
  from x, some_table
 where x.v not in some_table.value -- <- or whatever condition(s) required

You can do this with a subquery:

select st.*
from (select 1 as x from dual union all
      select 2 as x from dual union all
      select 10 as x from dual
     ) t left outer join
     some_table st left outer join
     on st.value = t.x
where st.value is null;
select to_number(regexp_substr(str, '[^,]+', 1, level)) ids
--put your comma-delimited list in the string below
  from (select '0,12,2,3,4,54,6,7,8,97' as str from dual)
connect by level <= length(regexp_replace(str, '[^,]+')) + 1
minus
--here comes select from some_table
select level from dual connect by level <= 10;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM