在给定的一组值上编写SQL查询

Gav*_*orn 1 sql oracle plsql plsqldeveloper

我正在尝试编写一个plsql查询,它允许我查询一组未存储在表中的已知值.假设这些已知值是以下字符串:

  • ABC
  • 高清
  • GHI
  • JKL

我想实现以下内容:


select * from [fill-in-the-blank] myvalues 
where not myvalues in 
(
    select id from dbtable
)

..我试图确定哪些知识值不在数据库表中.

约束

  • 这是pl/sql(oracle)
  • 此解决方案必须在Oracle PL/SQL Developer中运行
  • 我只对模式具有读访问权限,因此无法创建临时表.

有任何想法吗?

Joh*_*n N 5

您可以使用公用表表达式(CTE)来完成此任务:

with cte as (
    select 'abc' as id from dual
    union all
    select 'def' from dual
    union all
    select 'ghi' from dual
    union all
    select 'jkl' from dual
)
select * 
from cte
where not id in 
(
    select id from dbtable
)
Run Code Online (Sandbox Code Playgroud)

事实上,你可能根本不需要CTE(尽管我发现它有助于提高可读性):

select * 
from (
    select 'abc' as id from dual
    union all
    select 'def' from dual
    union all
    select 'ghi' from dual
    union all
    select 'jkl' from dual
)
where not id in 
(
    select id from dbtable
)
Run Code Online (Sandbox Code Playgroud)