哪个命令可以替换 Oracle 中 SQLServer 中的 IDENTITY INSERT ON/OFF?

发布于 2024-08-31 00:09:29 字数 338 浏览 2 评论 0原文

我必须将此查询(此处简化)从 T-SQL 迁移到 ORACLE

SET IDENTITY_INSERT table ON

INSERT INTO table (id, value) VALUES (1, 2)

SET IDENTITY_INSERT table OFF

id 作为 SQLServer 中的身份字段。

我在 ORACLE 中有一个带有序列的相同表,我找不到显示如何禁用该序列并将其设置为使用 MAX(id) + 1 重新启动的代码片段。

任何 ORACLE 专家都可以帮助我吗?

谢谢, 罗德里戈。

I have to migrate this query (simplified here) from T-SQL to ORACLE

SET IDENTITY_INSERT table ON

INSERT INTO table (id, value) VALUES (1, 2)

SET IDENTITY_INSERT table OFF

id being an Identity field in SQLServer.

I have the same table with a sequence in ORACLE, I couldn't find a snippet that shows how to disable the sequence and set it to start again with the MAX(id) + 1.

Any ORACLE expert can help me with this?

Thanks,
Rodrigo.

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

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

发布评论

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

评论(3

岛歌少女 2024-09-07 00:09:29

您不必在 Oracle 中禁用身份。由于您使用的是序列,因此请勿将其用于该插入。

也就是说,

insert into table (id, values) values (table_seq.nextval, 2)

您不必使用

insert into table (id, values) values (1, 2)

关于重新启动序列的第二个问题,我认为已经回答了 这里在SO中。

You don't have to disable the identity in Oracle. Since you are using sequences, just don't use it for that insert.

That is, instead of

insert into table (id, values) values (table_seq.nextval, 2)

you use

insert into table (id, values) values (1, 2)

As to your second question about restarting the sequence, I think that is answered here in SO.

扛起拖把扫天下 2024-09-07 00:09:29

以这种方式弄乱由 Oracle 序列填充的列似乎是一个坏主意。在 Oracle 中,您通常维护一个通过带有触发器的序列填充的列。如果您开始打开和关闭此功能,并重置序列即席,您将面临当另一个进程需要序列时序列不可用的风险,或者重置为已使用但未提交的值。

Messing with columns populated by Oracle sequences in this way seems like a Bad Idea. In Oracle, you are typically maintaining a column populated via sequences with a trigger. If you start turning this feature on and off, and resetting the sequence ad lib, you run the risk of a sequence not being available when another process needs it, or getting reset to a value that has been used already but not committed.

辞慾 2024-09-07 00:09:29

删除序列并在完成 max+1 值后重新创建它们。

Drop the sequences and re-create them when you're done with the max+1 value.

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