Oracle's easy-to-use implementation is self-growing

Source: Internet
Author: User

Sequences, triggers, and other related uses

SQL Server under Microsoft grows as long as the set column identity

Create Table  intIdentity(1,1primarykey not Nullvarchar();

MySQL to achieve self-growth as long as the set column auto_increment

Create Table  intprimarykeynotnullvarchar (15 ));

The Oracle database is a bit different, and does not have a self-growing column type like MySQL and SQL Server databases, but rather a sequence for uniqueness and self-growth.

Create Table Employee (       number,       varchar2(+),         VARCHAR2(max)       publishdate date,       number,         Constraintprimarykey(PID)       );

Sequence:

Create sequence Publish_autoinc      1  9999999999999999999999999999with 1                    by 1      NoCache;

Once you have defined the publish_autoinc sequence, you can access the Curval and Nextval properties of the sequence.
curval: Returns the current value of the sequence
nextval: Increase the value of the sequence first, and then return the sequence value

INSERT INTO employee values (publish_autoincnextval, 'ptitle1 ', 'pcontent1 ', sysdate,1);

Using triggers:

          Create or Replace Trigger insert_publish_autoinc      Insert   on Publish       for Each row           begin               Select  into  from dual;           End insert_publish_autoinc;                     

This automatically inserts the next value of the sequence into the PID whenever an insert operation is made to the Publish table, enabling self-growth.

END

Oracle's easy-to-use implementation is self-growing

Related Article

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.