Oracle enables auto-increment functionality

Source: Internet
Author: User

Imitate

1 Createsequence seq_id2MinValue13MaxValue999999994Start with 15Increment by 16 NoCache7 Order;8  9 To create a trigger:Ten   One Create Triggertri_test_id--(1) ABeforeInsert  onTest forEach row--test is a table name - begin - SelectSeq_id.nextval into: new.id fromdual; the Endtri_test_id; -   - Create or Replace Triggertri_test_id--(2) -BeforeInsert  onS_depart--S_depart is the table name +    forEach row - Declare +NextID Number; A begin at   IF: New. Departid is NULL or: New. Departid=0  Then --Departid is a column name -     SelectSeq_id.nextval--seq_id is exactly what you just created. -      intoNextID -      fromsys.dual; -: New. Departid:=NextID; -   End if; in Endtri_test_id;

Instance

1 CREATESEQUENCE rsk_book_filter_seq2INCREMENT by 1 3START with 10000 4 Nomaxvalue5 nocycle6 NOCACHE7 8 CREATE OR REPLACE TRIGGERRsk_book_filter_tri9BeforeINSERT  onRsk_book_filterTen  forEach ROW One BEGIN A SELECTRsk_book_filter_seq. Nextval into: NEW. risk_book_filter_id fromDUAL; - END;

Oracle enables auto-increment functionality

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.