Step for creating the auto-increment ID field in the oracle database, oracle Field

Source: Internet
Author: User

Step for creating the auto-increment ID field in the oracle database, oracle Field

The steps for using the auto-increment ID field in oracle are complex and summarized as follows:

-- Create a table

Create table advice (id int not null, active int default 1 not null, type int not null, MSG VARCHAR2 (512) not null, ADVICE VARCHAR2 (4000) not null, primary key (ID), CONSTRAINT ADVICE_UNI UNIQUE (TYPE, MSG) tablespace mydb; -- create an auto-incrementing ID named: table name_field name_seqcreate SEQUENCE ADVICE_ID_SEQ MINVALUE 1 nomaxvalue increment by 1 start with 1 NOCACHE; -- create a trigger for the Insert operation without writing NEXTVAL in the SQL statement, the table name is _ INS_TRGCREATE or replace trigger ADVICE_INS_TRG before insert on advice for each row when (NEW. id is null) BEGINSELECT ADVICE_ID_SEQ.NEXTVAL INTO: NEW. id from dual; END;

How to automatically add Oracle Database IDS

Create Sequence create sequence you must first have CREATE Sequence or Create ANY: = next_id; end; in this way, you do not need to specify the value of the column you want to auto-increment when inserting data ..

When you use java to add a record to an oracle database, an id field automatically increases.

The id automatically increases, and the value can be directly assigned to null in the program.

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.