oracle--trigger + sequence implementation self-increment

Source: Internet
Author: User

1 Create Tabletest_table (2Id Number PRIMARY KEY,3NAMEVARCHAR2(Ten),4NicknameVARCHAR2(Ten)5 )6 7 Createsequence Seq_test_trigger8MinValue19MaxValue999999999999999999999999999TenStart with 1 OneIncrement by 1; A  - Create TriggerTest_trigger -BeforeInsert  ontest_table the     forEach row -  when(new.id is NULL) - begin -     SelectSeq_test_trigger.nextval +      into: New.id -      fromdual; + End; A  at  - Create Triggertri_test_id -BeforeInsert  onTest_table--S_depart is the table name -    forEach row - Declare -NextID Number; in begin -   IF: new.id is NULL or: new.id=0  Then --Departid is a column name to     SelectSeq_test_trigger.nextval--S_s_depart is exactly what you just created. +      intoNextID -      fromdual; the: new.id:=NextID; *   End if; $ End;

Two create trigger modes, once created, you can insert data

oracle--trigger + sequence implementation self-increment

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.