How do I reset a sequence in Oracle?

后端 未结 18 1284
天命终不由人
天命终不由人 2020-11-22 05:09

In PostgreSQL, I can do something like this:

ALTER SEQUENCE serial RESTART WITH 0;

Is there an Oracle equivalent?

18条回答
  •  花落未央
    2020-11-22 05:51

    A true restart is not possible AFAIK. (Please correct me if I'm wrong!).

    However, if you want to set it to 0, you can just delete and recreate it.

    If you want to set it to a specific value, you can set the INCREMENT to a negative value and get the next value.

    That is, if your sequence is at 500, you can set it to 100 via

    ALTER SEQUENCE serial INCREMENT BY -400;
    SELECT serial.NEXTVAL FROM dual;
    ALTER SEQUENCE serial INCREMENT BY 1;
    

提交回复
热议问题