oracle 如何将序列中的下一个值放入变量中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6338198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:57:08  来源:igfitidea点击:

How do you get the next value in a sequence into a variable?

oraclesqlplussequences

提问by user439199

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

因此,我正在编写一个存储过程,但在将序列的下一个值放入变量时遇到了问题。

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

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

回答by Patrick Marchand

Something like this?

像这样的东西?

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;