如何将序列中的下一个值转换为变量?

如何将序列中的下一个值转换为变量?

问题描述:

因此,我正在编写存储过程,并且在将序列的下一个值转换为变量时遇到麻烦.

So I'm writing a stored procedure and am having trouble getting the next value of a sequence into a variable.

序列名称被传递到函数中并存储为varchar2变量.如何将该序列中的下一个值转换为局部变量.

The sequence name is passed into the function and is stored as a varchar2 variable. How can you get the next value in that sequence into a local variable.

像这样吗?

create or replace procedure next_val (p_sequence_name varchar2)
as

v_nextval integer;
v_select varchar2(100);

begin

v_select := 'select '||p_sequence_name||'.nextval from dual';

execute immediate v_select into v_nextval;

dbms_output.put_line('Nextval is: '||TO_CHAR(v_nextval));

end;