aspose file tools*
The moose likes JDBC and the fly likes Oracle - insert auto_seq Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Oracle - insert auto_seq" Watch "Oracle - insert auto_seq" New topic
Author

Oracle - insert auto_seq

Kris Reid
Ranch Hand

Joined: Jan 05, 2005
Posts: 247
Hi

Is there a way to get back in one query the auto inserted number for a query.
i.e.

At the moment I use 2 queries
INSERT INTO Blah (ID) VALUES (my_seq.NEXTVAL)

then:
select my_seq.currval from dual

Thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You could write a Stored Procedure to do this. It would still really be two SQL statements, but from the calling code's point of view it would only be one call.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Originally posted by Kris Reid:
Hi

Is there a way to get back in one query the auto inserted number for a query.
i.e.

At the moment I use 2 queries
INSERT INTO Blah (ID) VALUES (my_seq.NEXTVAL)

then:
select my_seq.currval from dual

Thanks


The only way I can think of to do it in one call is with a stored procedure.

However, if your goal is really to avoid the concurrency problems that the above approach has, you can merely shuffle things around a bit:


Each thread will retrieve a unique value from the sequence and return it to your Java code, where you can then do a normal insert.
Kris Reid
Ranch Hand

Joined: Jan 05, 2005
Posts: 247
Thanks guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Oracle - insert auto_seq