問題一:如何重置oracle序列
oracle序列創建以後,如果想重置序列從 0 開始,逐漸遞增1,可以采用如下存儲過程:
create or replace
procedure reset_seq( p_seq_name in varchar2 )
is
l_val number;
begin
execute immediate
'select ' || p_seq_name || '.nextval from dual' INTO l_val;
execute immediate
'alter sequence ' || p_seq_name || ' increment by -' || l_val ||
' minvalue 0';
execute immediate
'select ' || p_seq_name || '.nextval from dual' INTO l_val;
execute immediate
'alter sequence ' || p_seq_name || ' increment by 1 minvalue 0';
end;
/
執行傳入序列名稱即可:
execute reset_seq(‘test_seq’);
即可
參考: click here