开发者

Which command would replace IDENTITY INSERT ON/OFF from SQLServer in Oracle?

开发者 https://www.devze.com 2022-12-29 04:02 出处:网络
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)

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'开发者_如何学Pythont 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.


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消