Oracle Reset Sequence

Source: Internet
Author: User

Oracle resets the self-increment sequence to the initial value of 1 o'clock, and if it is removed and rebuilt, then the functions and stored procedures that depend on it are invalidated and need to be recompiled. The inverse process is used to change the increment value to (sequence) using the negative step parameter. Nextval-1), and then change back. Suppose you need to modify the sequence name: Seq_name1、SelectSeq_name.nextval fromDual//Assuming results are 56562、AlterSequence Seq_name increment by -5655;//Attention is-(n-1)3、SelectSeq_name.nextval fromDual//check again, walk, reset to 1.4、AlterSequence Seq_name increment by 1;//Restore the following is the stored procedure, incoming sequence name:CREATE OR REPLACE PROCEDURESeq_reset (v_seqnameVARCHAR2) asN Number(Ten); TSQLVARCHAR2( -);BEGIN  EXECUTEIMMEDIATE'Select' ||V_seqname|| '. Nextval from dual'     intoN; N:= -(N- 1); TSQL:= 'Alter sequence' ||V_seqname|| 'Increment by' ||N; EXECUTEIMMEDIATE TSQL; EXECUTEIMMEDIATE'Select' ||V_seqname|| '. Nextval from dual'     intoN; TSQL:= 'Alter sequence' ||V_seqname|| 'Increment by 1'; EXECUTEIMMEDIATE TSQL;ENDSeq_reset;

Oracle Reset Sequence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.