Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which command would replace IDENTITY INSERT ON/OFF from SQLServer in 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.

like image 374
rodrigoq Avatar asked May 03 '10 15:05

rodrigoq


1 Answers

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.

like image 50
MJB Avatar answered Sep 21 '22 18:09

MJB