How to increase the ID number in oracle

Source: Internet
Author: User

Generate primary key values using sequences.

Sequence is a database object that can be used by multiple users to generate a series of unique numbers. Sequence definition is stored in the data dictionary. You can use sequence to automatically generate the key value of a primary key by providing a sequence table with unique values. When a sequence is called for the first time, it returns a predetermined value. In each subsequent query, the sequence will generate a value that increases according to the specified increment. The sequence can be cyclically or continuously increased until the specified maximum value is reached.
Copy codeThe Code is as follows:
-- Create sequence
Create sequence seq_on_test
Increment by 1
Start with 1
Nomaxvalue
Nocycle
Nocache;

-- Create a table
Drop table test;
Create table test (
ID integer
, Stu_name nvarchar2 (4)
, Stu_age number
);

-- Insert data
Insert into test values (seq_on_test.nextval, 'Mary ', 15 );
Insert into test values (seq_on_test.nextval, 'Tom ', 16 );

Select * from test;

-- Result
/*
1 Mary 15
2 Tom 16
*/

-- Two methods of seq
Select seq_on_test.currval from dual;
Select seq_on_test.nextval from dual;

-- Result
/*
2
3
*/

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.