获取序列名称 (Oracle)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5560747/
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 23:16:36  来源:igfitidea点击:

Get Sequence Name (Oracle)?

javadatabaseoraclesequence

提问by Horus

I don't have access to see the database, but I have the ability to create database objects (via an xml file). The xml documentation says that if I set an attribute called "identity" to true then a sequence will be created. Is it possible for me to write logic that would return the name of the sequence so that I can use nextVal when I'm writing INSERT statements?

我无权查看数据库,但我可以创建数据库对象(通过 xml 文件)。xml 文档说,如果我将一个名为“identity”的属性设置为 true,那么将创建一个序列。我是否可以编写返回序列名称的逻辑,以便在编写 INSERT 语句时可以使用 nextVal?

Robert

罗伯特

Here's the documentation, do a find on the word "identity"...

这是文档,找到“身份”一词...

回答by Horus

If you can run select statements, then you might be able to try select * from user_sequences to get the names of sequences. Otherwise, could you please send the documentation for this database creation utility that you are using, if it is public. Otherwise, it will be very difficult to answer this question.

如果您可以运行 select 语句,那么您也许可以尝试 select * from user_sequences 来获取序列的名称。否则,您能否发送您正在使用的数据库创建实用程序的文档(如果它是公开的)。否则,这个问题将很难回答。

EDIT:

编辑:

After a review of the documentation, it said that if you created a table with a primary key, it would create a sequence with the following rules, quoted directly from the documentation:

在查看文档后,它说如果您创建一个带有主键的表,它将创建一个具有以下规则的序列,直接从文档中引用:

Primary keys must contain one columnref subelement that includes a single attribute, name, that references the column name to include in the primary key. In SQL Server, the key is mapped as an identity field with an auto-incremented value. On Oracle, a sequence is automatically created with the table name plus _seq suffix.

主键必须包含一个 columnref 子元素,该子元素包含一个属性 name,该属性引用要包含在主键中的列名。在 SQL Server 中,键被映射为具有自动递增值的标识字段。在 Oracle 上,使用表名加上 _seq 后缀自动创建一个序列。

Thus, your query would be:

因此,您的查询将是:

select * from all_sequences where sequence_name = upper(tablename || '_SEQ');

select * from all_sequences where sequence_name = upper(tablename || '_SEQ');