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

后端 未结 7 919
既然无缘
既然无缘 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:33

    I'm not sure there is a good way to do it, this isn't really what sequences are designed for. they are just purely incrementing unique numbers.

    2 thoughts come to mind.

    1. At 12am on the first, reset the sequence, this is hard, because you need to make sure you beat any code.
    2. Create a sequence for each year, perhaps even have it in your code to be able to create the sequence, then dynamically call the correct sequence for the year.

    I'd tend to favor option 2, as its not trying to do anything fancy and is always going to work without fail, any options trying to manipulate the sequence itself are bound to bite you.

提交回复
热议问题