Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从表-SQL查询空值_Sql_Oracle11g - Fatal编程技术网

从表-SQL查询空值

从表-SQL查询空值,sql,oracle11g,Sql,Oracle11g,我有一个表,它有一个引用id列。此引用id列包含某些行的主键。现在我想从表中筛选所有包含NULL的rest值。 表格 PK REFERENCE_ID 1 1 2 NULL 3 3 4 NULL 5 ab 下面的查询带来了所有具有reference\u id的结果,但我想获取reference\u id列的所有空值 select count(*)from table where table.ID not in (selec

我有一个表,它有一个引用id列。此引用id列包含某些行的主键。现在我想从表中筛选所有包含NULL的rest值。
表格

PK   REFERENCE_ID
1        1
2        NULL
3        3
4        NULL
5        ab
下面的查询带来了所有具有reference\u id的结果,但我想获取reference\u id列的所有空值

select count(*)from table where table.ID not in (select table.reference_id from person)
我曾经用过存在,但也没有用。重要的是,我要参考PK搜索它,因为我想从列引用ID(PK除外)中获取包括空值在内的所有值。

您尝试过:

SELECT Reference_ID
FROM Table
WHERE Reference_ID IS NULL;

也许我还不清楚您想做什么,但将原始查询的元素与
IS NULL
组合起来是否可行

SELECT PK, Reference_ID
FROM table 
WHERE table.Reference_ID NOT IN (select PK from table)
  OR table.Reference_ID IS NULL
编辑:我不确定Reference\u ID字段中的“ab”。如果Reference_ID是一个varchar或类似的字段,您可能需要这样做:

SELECT PK, Reference_ID
FROM table 
WHERE table.Reference_ID NOT IN (select cast(PK as varchar(5)) from table)
  OR table.Reference_ID IS NULL

嗯,是空的吗@阿德尔谢谢,但这不是我所需要的。什么是“搜索它与PK的参考”的意思?为什么重要?根据您的示例数据,您希望查询返回什么?我想从列引用_ID(PK除外)中获取所有值,包括空值。谢谢,但重要的是,我要参考PK搜索它。