Reset a Sequence according to the year not by min or max value

后端 未结 1 506
北恋
北恋 2021-01-17 08:07

Create a sequence which will reset according to the year. Consider the sequence with 9 digit starts with 000000001 and max is 999999999.

Let Date is 30/12/2017 and

相关标签:
1条回答
  • 2021-01-17 09:03

    Create a recurring scheduled job that resets the sequence at midnight of 1st January each year.

    Something like (assuming you have a YOUR_SCHEMA.RESET_ANNUAL_SEQUENCE procedure to perform the reset):

    BEGIN
      DBMS_SCHEDULER.CREATE_JOB (
        job_name             => 'reset_annual_sequence_job',
        job_type             => 'PLSQL_BLOCK',
        job_action           => 'BEGIN your_schema.reset_annual_sequence; END;',
        start_date           => ADD_MONTHS( TRUNC( SYSTIMESTAMP, 'YY' ), 12 ),
        repeat_interval      => 'FREQ=YEARLY; BYDATE=0101;', 
        enabled              =>  TRUE,
        comments             => 'Annual sequence reset'
      );
    END;
    /
    
    0 讨论(0)
提交回复
热议问题