哪个命令可以替换 Oracle 中 SQLServer 中的 IDENTITY INSERT ON/OFF?
我必须将此查询(此处简化)从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不必在 Oracle 中禁用身份。由于您使用的是序列,因此请勿将其用于该插入。
也就是说,
您不必使用
关于重新启动序列的第二个问题,我认为已经回答了 这里在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
you use
As to your second question about restarting the sequence, I think that is answered here in SO.
以这种方式弄乱由 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.
删除序列并在完成 max+1 值后重新创建它们。
Drop the sequences and re-create them when you're done with the max+1 value.