调整Oracle序列为指定的值存储过程

CREATE OR REPLACE procedure AdjustSeqValue(pSeqName in varchar2,pValue in number) is
/******************************************************************************
序列必须存在,且为NOCACHE
wallimn 2009-11-06 
******************************************************************************/
v_value number;
v_tmp	number;
begin
	select last_number into v_value from seq where sequence_name=upper(pSeqName);
	if(v_value=pValue) then
		return;
	end if;
	
	if( v_value>pValue) then
		execute immediate 'drop sequence '||pSeqName;
		execute immediate 'create sequence '||pSeqName || ' NOCACHE ';
		v_value:=1;
	end if;
	
	for i in v_value..pValue-1 loop
		execute immediate 'select '||pSeqName||'.nextval from dual' into v_tmp;
	end loop;
end AdjustSeqValue;

你可能感兴趣的:(oracle,sql)