在一条语句中从序列中查询多个NEXTVAL [英] Query several NEXTVAL from sequence in one statement
问题描述
基本上,我需要从一个序列中查询大约一千个NEXTVAL.我可以循环查询它们,也可以通过具有较大表的联接查询它们.
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.
有没有更简单的方法?
更新. 基本上,我有一个对象操作时间表.每个对象都有一个生成的UUID或数据库中的ID.在计算出最佳计划后,我需要将其写入数据库,但是表中的每个ID都必须来自序列.因此,我需要从该序列中查询一些ID.问题是循环查询的速度很慢,因为数据库确实离我很远,而且在循环中执行数十个查询时我不能只松散几秒钟.因此,我需要在一次查询中查询所有这些新ID.
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.
推荐答案
您可以使用:
select your_sequence.nextval
from (
select level
from dual
connect by level < 1000
);
这篇关于在一条语句中从序列中查询多个NEXTVAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!