plsql - Stored procedure to return a list of sequence IDs -
i need little stored procedure following logic?
procedure_name(seq_name in varchar2(50), block_count in int, return_ids out)
loop 1 block_count
return_ids := select 'seq_name'||.nextval dual;
end loop
return return_ids
basically want have stored procedure lets me pass in sequence name, how many ids need , return me generated listed of ids can use in java. reason me return list of ids can use in java , no 1 else using sequence ids. used in other bulk inserts later down line. in essence, reserve block of sequence ids.
here 1 way return array pl/sql procedure.
create collection type of numbers, initialize in procedure , populate numbers return. example:
create or replace type narray table of number; create or replace procedure get_seq_ids(seq_name in varchar2, block_count in number, return_ids out narray) begin return_ids := narray(); return_ids.extend(block_count); in 1 .. block_count loop execute immediate 'select ' || seq_name || '.nextval dual' return_ids(i); end loop; end; /
Comments
Post a Comment