如何获取 table 中的所有非空列
How to get all not null columns in a table
我需要在 table 中找到所有非空列。比如我的table就是下面那个
假设,Column1、Column2 和 Column3 具有非空约束,而 Column4、Column5 和 Column6 是可空类型。 Oracle 中是否有任何查询列出非空类型的列名,即我需要获取列名 Column1、Column2 和 Column3。
期望输出
Column1
Column2
Column3
我知道应该有一个简单的方法来实现这一点,但我是 Oracle 的新手。任何帮助将不胜感激。
可以查询all_tab_columns
table:
select column_name
from all_tab_columns
where table_name = 'TABLE1'
and nullable = 'N';
I know there should be a simple way to achieve this, but am new to 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'
我需要在 table 中找到所有非空列。比如我的table就是下面那个
假设,Column1、Column2 和 Column3 具有非空约束,而 Column4、Column5 和 Column6 是可空类型。 Oracle 中是否有任何查询列出非空类型的列名,即我需要获取列名 Column1、Column2 和 Column3。
期望输出
Column1
Column2
Column3
我知道应该有一个简单的方法来实现这一点,但我是 Oracle 的新手。任何帮助将不胜感激。
可以查询all_tab_columns
table:
select column_name
from all_tab_columns
where table_name = 'TABLE1'
and nullable = 'N';
I know there should be a simple way to achieve this, but am new to 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'