作者:忘爱LIAN | 来源:互联网 | 2014-07-08 01:11
Oracle重置sequence语句1Sql代码www.2cto.comDECLAREnNUMBER(10);tsqlVARCHAR2(100);p_seqNamevarchar2(20);BEGINp_seqName:'SEQ_RUN_ID';...
Sql代码 www.2cto.com
DECLARE
n NUMBER(10 );
tsql VARCHAR2(100 );
p_seqName varchar2(20 );
BEGIN
p_seqName := 'SEQ_RUN_ID';
EXECUTE IMMEDIATE 'SELECT ' || p_seqName || '.NEXTVAL FROM dual ' INTO n;
n := - (n - 1);
tsql := 'alter sequence '|| p_seqName ||' increment by ' || n;
EXECUTE IMMEDIATE tsql;
EXECUTE IMMEDIATE 'SELECT ' || p_seqName || '.NEXTVAL FROM dual ' INTO n;
tsql := 'alter sequence '|| p_seqName ||' increment by 1' ;
EXECUTE IMMEDIATE tsql;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( SQLERRM);
END;