Initial value of Oracle change sequence ____oracle

Source: Internet
Author: User
DECLARE v_in VARCHAR2 (1024); V_start Int;v_end int; V_table varchar2, V_seq varchar2, v_table_seq varchar2 (MB)
    ; Begin
      v_table:= ' JX_KHFA ';--table name
      v_seq:= ' SEQ_JX_KHFA ';--sequence name
      v_table_seq:= ' id ';--table field corresponding sequence
     v_in:= ' Select Max (' | | v_table_seq| | ') From ' | | The maximum value in the v_table;--query table is
    execute immediate v_in into V_start;
     v_in:= ' SELECT ' | | v_seq| | '. Nextval from dual ';-Query the next sequence value
    execute immediate v_in into V_end;
      v_in:= ' ALTER SEQUENCE ' | | v_seq| | ' INCREMENT by ' | | To_char (v_start-v_end+1);--Change step length
     execute immediate v_in;
    Execute immediate ' SELECT ' | | v_seq| | '. Nextval from dual ' into v_end;--executes a sequence
    execute immediate ' ALTER SEQUENCE ' | | v_seq| | ' INCREMENT by 1 ';--change back to step end
      ;

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.