background image
<< TableExpression | The DEFAULT keyword >>

NEXT VALUE FOR expression

<< TableExpression | The DEFAULT keyword >>
Derby Reference Manual
94
TableViewOrFunctionExpression
{
{
table-Name
|
view-Name
}
[ CorrelationClause ]
|
{
TableSubquery
|
TableFunctionInvocation
}
CorrelationClause
}
where CorrelationClause is
[ AS ]
correlation-Name
[ (
Simple-column-Name
[ ,
Simple-column-Name
]* ) ]
TableFunctionInvocation:
TABLE function-name( [ [ function-arg ] [, function-arg ]* ] )
Note that when you invoke a table function, you must bind it to a correlation name. For
example:
SELECT s.*
FROM TABLE( externalEmployees( 42 ) ) s
NEXT VALUE FOR expression
The NEXT VALUE FOR expression retrieves the next value from a sequence generator
that was created with a
CREATE SEQUENCE statement
.
Syntax
NEXT VALUE FOR
sequenceName
If this is the first use of the sequence generator, the generator returns its START
value. Otherwise, the INCREMENT value is added to the previous value returned by
the sequence generator. The data type of the value is the dataType specified for the
sequence generator.
If the sequence generator wraps around, then one of the following happens:
· If the sequence generator was created using the CYCLE keyword, the sequence
generator is reset to its START value.
· If the sequence generator was created with the default NO CYCLE behavior, Derby
throws an exception.
In order to retrieve the next value of a sequence generator, you or your session's current
role must have USAGE privilege on the generator.
A NEXT VALUE FOR expression may occur in the following places:
·
SELECT statement
: As part of the expression defining a returned column in a
SELECT list
·
VALUES expression
: As part of the expression defining a column in a row
constructor (VALUES expression)
·
UPDATE statement
; As part of the expression defining the new value to which a
column is being set
Only one NEXT VALUE FOR expression is allowed per sequence per statement.
The NEXT VALUE FOR expression is not allowed in any statement which has a
DISTINCT or ORDER BY expression.