This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Using Sequence to populate ID(SOLVED) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Using Sequence to populate ID(SOLVED)" Watch "Using Sequence to populate ID(SOLVED)" New topic

Using Sequence to populate ID(SOLVED)

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 484

I have never used sequences in pl sql before, so I am just wondering if it is best practice to use seq.nextval or seq.currval?

I do not know if using .currval will use the current number, and then the next time it is used ti will use the next number in line, or if .currval will keep using the same number over and over again.

Thanks for any advice

edit - I know I can easily answer this question by testing it out, but I am also looking for any best practice tips for using sequences since I have never used one.

True wisdom is in knowing you know nothing - Socrates
Jan Cumps

Joined: Dec 20, 2006
Posts: 2562

you have to use nextval to retrieve the unique sequence value.

After that, curval will return the value created by that nextval call.

curval only works after you have called nextval.

OCUP UML fundamental and ITIL foundation
I agree. Here's the link:
subject: Using Sequence to populate ID(SOLVED)
jQuery in Action, 3rd edition