新到Oracle和这里使用Oracle 12c中,我与他们IDENTITY列的几桌,我怎么计算出,如果塔上的标识类型是"始终产生"或" DEFAULT"?是否有我可以查询的特定于身份的元数据系统表?
谢谢!
答案 0 :(得分:1)
目录视图USER_TAB_IDENTITY_COLS
(或ALL_
或DBA_
取决于您的需求以及您拥有的权限)将为您提供所需的信息。
但是,如果您想区分BY DEFAULT
和BY DEFAULT ON NULL
,则需要查询*_TAB_COLUMNS
次观看。
两个视图都没有可能需要的所有可能信息 - 您需要查询两个视图以获取所有详细信息。
create table s ( x number generated always as identity);
create table t ( y number generated by default as identity);
create table u ( z number generated by default on null as identity);
select table_name, column_name, generation_type
from user_tab_identity_cols
where table_name in ('S', 'T', 'U')
;
TABLE_NAME COLUMN_NAME GENERATION_TYPE
------------ ------------ ---------------
S X ALWAYS
T Y BY DEFAULT
U Z BY DEFAULT
select table_name, column_name, identity_column, default_on_null
from user_tab_columns
where table_name in ('S', 'T', 'U')
;
TABLE_NAME COLUMN_NAME IDENTITY_COLUMN DEFAULT_ON_NULL
------------ ------------ --------------- ---------------
S X YES NO
T Y YES NO
U Z YES YES