oracle oracle中如何判断一列是否为自增字段?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5050072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:49:10  来源:igfitidea点击:

How to find out if a column is an auto increment field in oracle?

sqloraclemetadataprimary-keysqlplus

提问by nakiya

How to find out if a column is an auto increment field in oracle?

oracle中如何判断一列是否为自增字段?

回答by GolezTrol

You can't. Oracle doesn't have auto-increment fields.

你不能。Oracle 没有自动增量字段。

Oracle supports sequences, which are separate database objects for generating numbers. These seuqences can be used in the insert statement or in a before insert trigger to generate a primary key value for the new record.

Oracle 支持序列,它们是用于生成数字的独立数据库对象。这些序列可以在插入语句或插入前触发器中使用,以生成新记录的主键值。

The fields themselves are just normal field and there is no relation between the sequence and the field.

字段本身只是普通字段,序列和字段之间没有关系。

So the only hope is to parse a trigger and see if you can find evidence of it being filled there using a sequence. That would be a tough job, though, and I doubt if you can make this reliable enough. After all, the trigger could fire a function which returns the value, so you have to go all the way if you want to be sure.

所以唯一的希望是解析一个触发器,看看是否可以找到使用序列填充它的证据。不过,这将是一项艰巨的工作,我怀疑您是否能让它足够可靠。毕竟,触发器可以触发一个返回值的函数,所以如果你想确定的话,你必须一路走下去。

回答by user3861225

As of Oracle 12.1 identity columns (with self generated sequences) can be identified by looking at the "DATA_DEFAULT" column of view DBA_TAB_COLUMS (or USER_TAB_COLUMNS or ALL_TAB_COLUMNS). They will look like "#OWNER"."ISEQ$$_nnnnn".nextval

从 Oracle 12.1 开始,可以通过查看视图 DBA_TAB_COLUMS(或 USER_TAB_COLUMNS 或 ALL_TAB_COLUMNS)的“DATA_DEFAULT”列来识别身份列(带有自生成的序列)。它们看起来像 "#OWNER"."ISEQ$$_nnnnn".nextval