How do I automatically reset a sequence's value to 0 every year in Oracle 10g?

后端 未结 7 844
既然无缘
既然无缘 2021-01-02 22:09

As in the question, how do I automatically reset an Oracle sequence\'s value back to 0 every year in Oracle 10g?

I\'m using the sequence to generate an identifier i

7条回答
  •  清酒与你
    2021-01-02 22:45

    First of all, it doesn't seem to be a way to make the sequence restart automatically every year. Read this for reference:

    http://www.psoug.org/reference/OLD/sequences.html?PHPSESSID=5949da378678fa6d24b6fcc6eaae9888

    My approach will be:

    1. create a table with the year and the starting sequence for that year (lets call this table year_seed)

    2. create a procedure that receives the year, checks the year_seed table and if it's the first check for the year generates the register with the starting sequence. This procedure must also return the sequence minus the starting sequence for the year.

    Maybe it's not so simple but I think it's the best solution. Good luck

提交回复
热议问题