Saying that you just call sequence.nextval several times will be boring, so here is what you can try:
create type t_num_tab as table of number; CREATE SEQUENCE SEQ_TEST START WITH 1 MAXVALUE 999999999999999999999999999 MINVALUE 1 NOCYCLE CACHE 100 NOORDER; create or replace function get_seq_vals(i_num in number) return t_num_tab is seq_tab t_num_tab; begin select SEQ_TEST.nextval bulk collect into seq_tab from all_objects where rownum <= i_num; return seq_tab; end;
And you can use it as follows. In this example, 7 numbers are sequentially drawn from the sequence:
declare numbers t_num_tab; idx number; begin
Also note that I use "next" instead of first..last, since this is possible, you might want to remove numbers from the list before iterating (or, sometimes, the sequence cache can increase the numbers by more than 1).
tbone source share