如何从雪花序列中获取数字块

How to get a block of number from snowflake sequence

我只看到这种获取序列号的方法。但我想得到一块。 select seq1.nextval 来自 dual;

您可以使用雪花 generator 生成行,然后使用 seq.nextval 获取序列块。我想这就是你的意思:

-- Create the sequence
create or replace sequence seq1;

-- Generate the block
select
    s.nextval
from table (generator(rowcount => 10)) v,
     table (getnextval(seq1)) s
order by 1;

上面的输出select:

+-------+
|NEXTVAL|
+-------+
|1      |
|2      |
|3      |
|4      |
|5      |
|6      |
|7      |
|8      |
|9      |
|10     |
+-------+

了解 semantics of sequences 很重要。序列不一定像本例中那样按顺序生成(没有间隙),但它们始终是唯一的。

来自上面链接的文档:

There is no guarantee that values from a sequence are contiguous (gap-free) or that the sequence values are assigned in a particular order. There is, in fact, no way to assign values from a sequence to rows in a specified order other than to use single-row statements (this still provides no guarantee about gaps).