作者:领悟人生的悲欢喜乐_829 | 来源:互联网 | 2014-07-08 01:11
Oracle重置sequence语句2Sql代码www.2cto.comCREATEORREPLACEPROCEDURERESET_SEQUENCE(p_sSeqNameINVARCHAR2)ISnNUMBER(10);tsqlVARCHAR2(100);BEGINEXECUTE...
Sql代码 www.2cto.com
CREATE OR REPLACE PROCEDURE RESET_SEQUENCE(p_sSeqName IN VARCHAR2)
IS
n NUMBER(10 );
tsql VARCHAR2(100 );
BEGIN
EXECUTE IMMEDIATE 'SELECT ' || p_sSeqName || '.NEXTVAL FROM dual '
INTO n;
n := - (n - 1);
tsql := 'alter sequence ' || p_sSeqName || ' increment by ' || n;
EXECUTE IMMEDIATE tsql;
EXECUTE IMMEDIATE 'SELECT ' || p_sSeqName || '.NEXTVAL FROM dual '
INTO n;
tsql := 'alter sequence ' || p_sSeqName || ' increment by 1' ;
EXECUTE IMMEDIATE tsql;
EXCEPTION WHEN OTHERS THEN
NULL;
END RESET_SEQUENCE;