In SQL Server you can select the next value from a sequence like this:
select next value for MY_SEQ
If you don't suppress the table from which to select, for every row the next value will be outputted:
select next value for MY_SEQ
from MY_TABLE
[2020-09-08 15:47:34] 350 rows retrieved starting from 1 in 102 ms (execution: 62 ms, fetching: 40 ms)
How can I select the next n
values for a sequence?
In Oracle this would look like that:
select MY_SEQ.nextval
from (
select level
from dual
connect by level < 10
)
I tried something like this:
select top(10) next value for MY_SEQ
But the result was:
[S0001][11739] NEXT VALUE FOR function cannot be used if ROWCOUNT option has been set, or the query contains TOP or OFFSET.
I guess I could create a temporary table with n
rows and select from that, but this wouldn't be an especially elegant solution.