获取序列名称 (Oracle)?

发布于 2024-10-30 19:05:48 字数 254 浏览 4 评论 0原文

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

罗伯特

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

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?

Robert

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

审判长 2024-11-06 19:05:48

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

编辑:

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

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

因此,您的查询将是:

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

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.

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.

Thus, your query would be:

select * from all_sequences where sequence_name = upper(tablename || '_SEQ');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文