How to Create auto-incrementing fields in Oracle

Source: Internet
Author: User

Originally published on Netease blog 17:30:17

MySQL was previously viewed at school and used for a period of time. It is relatively simple to create an auto-incrementing field in MySQL.
For example, in the table creation statement, Id int key auto_increment. At last, fill in the corresponding fields during insert.
However, in Oracle, we haven't seen people around us directly create an auto-incrementing field. I searched the internet and said it was not supported in many documents. to implement auto-increment fields, you can only implement them in other ways. for example, sequence.
Create sequence seq_test minvalue 1 maxvalue 99999 start with 1 increment by 1 cycle nocache;

Cycle indicates that the cycle starts from the minimum value after the maximum value is reached. nocache does not cache the sequence value.
In this way, you can enter sequence. nextval in the corresponding position when inserting a record. You can also use sequence. currval to view the current sequence value.

The difference is that if sequence has not been called. nextval, sequnce is called. currval reports an error. call sequence. nextval increases the Sequence Value and returns the current value. sequence. currval does not change the sequence value.

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.