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

So, I am writing a stored procedure, and it is difficult for me to get the next sequence value in a variable.

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

+7
source share
1 answer

Something like that?

 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; 
+13
source

All Articles