Self-increment field settings in Oracle

Source: Internet
Author: User

As we all know, this is very pit, especially used in MySQL's Self-increment field settings, the result is not in Oracle. Oh,no

I am using the 12c version, it has a new feature, you can set the self-increment sequence, in the creation table is, set the ID as the self-increment sequence

CREATE TABLE T
(
ID number generated by default as identity (start with 1 increment by 1),
Name VARCHAR2 (20),
Password VARCHAR2 (20),
Constraint pk_t Primary Key (Id)
);

Very worried Mulberry is a companion with 11g, that can only be achieved by sequence + trigger;

Create a table

-create Table T
(
ID number,
Name VARCHAR2 (20),
Password VARCHAR2 (20),
Constraint pk_t Primary Key (Id)
);

CREATE SEQUENCE seq_t----------------/* Sequence name */
INCREMENT by 1----------------/* self-increment 1*/
Start with 1----------------/* Starting from 1 */
Nomaxvalue----------------/* Does not have a maximum value */
Nocycle
NOCACHE;
Create TRIGGER tri_t before------------------/* Creating trigger */
INSERT on T for each ROW if (new.id is null)
Begin
Select Seq_t.nextval into:new.id from dual;
End

Self-increment field settings 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.