
SELECT NEXT VALUE FOR MYLIB.BY_THREE AS "Next" The kernel of the error is:Ī NEXT VALUE expression must be evaluated before a PREVIOUS VALUEĪs the name suggests NEXT VALUE gets the next sequence number from the Sequence. When I run this statement I get an error message, SQL0845 or SQL code -845. The only I found to do this is using the SELECT PREVIOUS VALUE as in: If anyone from IBM is reading this the addition of the "Current Value" column would be very useful. Alas, Db2 for i does not have such a column.

Many other databases have a column in their SEQUENCES that contains the "Current Value" (last used) sequence number. This is the first question I thought of when I started "playing" with Sequences.

What was the last used value in the Sequence? The SEQNBR has been given the next sequence number generated by the Sequence. VALUES('ALPHA',NEXT VALUE FOR MYLIB.BY_TEN), If I wanted to update a row when I inserted I would do: In the previous post I update all the rows in a table. MAXIMUM_VALUE CYCLE_OPTION DATA_TYPE NUMERIC_PRECISION SEQUENCE_SCHEMA SEQUENCE_NAME START_VALUE INCREMENT MINIMUM_VALUE One of the things I like about the columns' long names in the SQL Views is that they are so descriptive when I show the results you will know what each of those columns contain. In this example I am only concerned with the Sequences in my library, MYLIB: I am not going to list all of the columns here, if you want to know what they are click on the link to the IBM documentation at the bottom of this post. Fortunately in Db2 there is a view I can use: SEQUENCES. How do I know what Sequences are out there?Īs I am using Sequences there must be a way to know what ones there are on this IBM i partition.

Having had a chance to "play" with them some more I wanted to write about what I have discovered.īefore I go into any examples I need to have some Sequences to "play" with: Last week I wrote a post introducing what SQL Sequences are.
