Using SEQUENCE in a Java servlet
How do I use SEQUENCE for a column when I am issuing an INSERT command? I am using the command in a JAVA servlet.
With each sequence, there is a psuedo-column called NEXTVAL. This gets the sequence's next value. Assume I have a sequence called MY_SEQ. Then to insert a value into a table, I might use a statement like this:
INSERT INTO my_table VALUES (my_seq.NEXTVAL, 'bob');When Oracle sees "my_seq.NEXTVAL" it gets the next value from the sequence and automatically updates the sequence counter for the next transaction.
For More Information
- Dozens more answers to tough Oracle questions from Brian Peasland are available.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.