Basically, I need to query about a thousand NEXTVAL from a sequence. I can query them in a loop, or I can query them through a join with a reeeeeally big table.
Is there any less hacky way?
Upd. Basically, I have a schedule of operations on objects. Each object has either a generated UUID, or an ID from database. After I calculate an optimal schedule, I need to write it into DB, but every ID in the table HAS to be from a sequence. So I need to query some IDs from that sequence. The problem is that looping query is slow, since the DB is really far from me, and I can't just loose several seconds while executing dozens of queries in a loop. So I need to query all those new IDs in one query.
If you want to select the next value from sequence object, you can use this SQL statement. If you want to select multiple next values from SQL Sequence, you have to loop calling the above SQL statement and save the "next value" got in a storage. You can loop using (while loop) or by (cursor).
You can access the value of a sequence using the NEXTVAL or CURRVAL operators in SQL statements. You must qualify NEXTVAL or CURRVAL with the name (or synonym) of a sequence object that exists in the same database, using the format sequence. NEXTVAL or sequence. CURRVAL.
When you create a sequence, you can define its initial value and the increment between its values. The first reference to NEXTVAL returns the sequence's initial value. Subsequent references to NEXTVAL increment the sequence value by the defined increment and return the new value.
The syntax to a view the properties of a sequence in SQL Server (Transact-SQL) is: SELECT * FROM sys. sequences WHERE name = 'sequence_name'; sequence_name.
You can use this:
select your_sequence.nextval from ( select level from dual connect by level < 1000 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With