Oracle 重置sequence2

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;
  

你可能感兴趣的:(oracle)