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

谁说胖子不能爱 提交于 2019-12-09 17:28:30

问题


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 varchar2 variable. How can you get the next value in that sequence into a local variable.


回答1:


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;


来源:https://stackoverflow.com/questions/6338198/how-do-you-get-the-next-value-in-a-sequence-into-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!