How to change the Oracle Sequence Value using loop

declare
  l_MaxVal  pls_integer;
  l_Currval pls_integer default - 1;
begin
  select max(column_using_sequence)
    into l_MaxVal
    from table_name;
  while l_Currval < l_Maxval
  loop
    select sequence_name.nextval
      into l_Currval
      from dual;
  end loop;
end;

Example:
declare
  l_MaxVal  pls_integer;
  l_Currval pls_integer default - 1;
begin
  select max(ACCOUNTID)
    into l_MaxVal
    from ACCOUNT;
  while l_Currval < l_Maxval
  loop
    select ACCOUNT_SEQ.nextval
      into l_Currval
      from dual;
  end loop;
end;

Comments