Self-increment-sequence-sequence in Oracle

Source: Internet
Author: User

None of the previous versions of Oracle 12c are self-contained, and if you need to use a self-add column, you need to sequence.

DROP TABLE CustomerOrder PURGE;

CREATE TABLE CustomerOrder

(

ORDERID number is not NULL,

PRODUCTID number,

PRODUCTNAME VARCHAR2 (50),

CONSTRAINTS Pk_orderid PRIMARY KEY (ORDERID)

);

DROP SEQUENCE Sq_orderid;

CREATE SEQUENCE Sq_orderid

START with 10000000000000;

The above code creates a commodity purchase table, and a sequence with a starting number of 10000000000000.

The Nextval method must be called before it can be used immediately after the sequence has been successfully created for the first time.

SELECT Sq_orderid. Nextval from DUAL;

You can then use the sequence to set values for the table data:

INSERT into CustomerOrder (orderid,productid,productname)

VALUES (Sq_orderid. nextval,888, ' Nice ');

INSERT into CustomerOrder (orderid,productid,productname)

VALUES (Sq_orderid. nextval,999, ' Jie Rou ');

Self-increment-sequence-sequence in Oracle

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.