如何获取表中的所有非空列

问题描述 投票:0回答:2

我需要在表中查找所有非空列。例如,我的表格如下

enter image description here

可以说,Column1,Column2和Column3具有非空约束,Column4,Column5和Column6具有可空类型。在Oracle中是否有任何查询列出非空类型的列名,即我需要获取列名Column1,Column2和Column3。

期望的输出

Column1
Column2
Column3

我知道应该有一个简单的方法来实现这一点,但对Oracle来说是新手。任何帮助将受到高度赞赏。

oracle oracle11g oracle10g constraints notnull
2个回答
6
投票

您可以查询all_tab_columns表:

select column_name
from all_tab_columns
where table_name = 'TABLE1'
and nullable = 'N';

2
投票

我知道应该有一个简单的方法来实现这一点,但对Oracle来说是新手。

那么,online documentation正是你需要研究的。

根据权限,您需要查看[DBA | USER | ALL] _TAB_COLUMNS。

ALL_TAB_COLUMNS

Column      Datatype        Description
NULLABLE    VARCHAR2(1)     Indicates whether a column allows NULLs. 
                            The value is N if there is a NOT NULL constraint
                            on the column or if the column is part of a PRIMARY KEY. 
                            The constraint should be in an ENABLE VALIDATE state.

因此,根据文档,您需要使用过滤器:

NULLABLE = 'N'
© www.soinside.com 2019 - 2024. All rights reserved.