Sql 使用where变量返回空结果

Sql 使用where变量返回空结果,sql,oracle,select,Sql,Oracle,Select,如果结果返回空值,我想查看我在where子句中使用的值 select * from (select PartNum, PONum from db where PartNum = '12345' and PONum = 'POX123' union select PartNum, PONum from db where PartNum = '67890' and PONum = 'POX456' union select PartNum, PONum from db

如果结果返回空值,我想查看我在where子句中使用的值

 select *
 from (select PartNum, PONum from db where PartNum = '12345' and PONum = 'POX123' union
       select PartNum, PONum from db where PartNum = '67890' and PONum = 'POX456' union
       select PartNum, PONum from db where PartNum = '98765' and PONum = 'POX789') d
 where PartNum is null

PartNum 98765不在db中,这就是我需要返回到其他地方进行比较的地方,这显然不起作用,但我无法理解如何返回空行,这似乎违反直觉

您可以枚举这些值,然后使用not exists或反左联接筛选表中不存在的值

在SQL Server中:

select p.partNum
from (values (12345), (67890), (98765)) p(partNum)
where not exists (select 1 from db d where d.partNum = p.partNum)
在Oracle中:

select p.partNum
from (
    select 12345 partNum from dual
    union all select 67890 from dual
    union all select 98765 from dual
) p
where not exists (select 1 from db d where d.partNum = p.partNum)

请注意,这将partNum视为一个数字,因为它看起来确实像一个数字。如果它实际上是一个类似字符串的数据类型,那么您可以用单引号将值括起来。

Oracle或SQL Server?请只保留相关的数据库标签。公正的评论…甲骨文的胜利。这对我来说都是可行的。我能理解这一点,这一点让我向前迈进。只需要轻轻一推。谢谢。我的具体问题和问题已经解决了。再次感谢