About setting the system number SYSID automatic numbering in Oracle;

Source: Internet
Author: User


http://liye9801.blog.163.com/blog/static/601970320086210039591/How to set up automatic numbering columns in Oracle

2008-07-21 12:00:39| Category: Oracle | Tags: | Font size Big medium small subscription

We know there is no such type in Oracle! So we can only think of other ways!
趏 Raclek, for convenience I often use a combination of triggers and sequences to achieve, the following is an example, I hope to help the brothers ...
First build the table, re-build the sequence, then the trigger, and finally test

============================================= 
--Specifies the sequence number  
-- 2003-10-8 15:53 
============================================= 

Conn scott/ti[email protected]  

drop table Foo;  

CREATE Table foo ( 
ID number primary Key, 
Data varchar2 (100));  

Create Sequence < Span style= "color: #ff0000;" >foo_seq ; &NBSP;

Create or replace Trigger  bifer_foo_id_pk


Before insert
on Foo
For each row
Begin
Select Foo_seq.nextval into:new.id from dual;
End
/

For testing use:

INSERT into foo (data)
VALUES (' Chirstopher ');

INSERT into foo (id,data)
VALUES (5, ' Sean ');

SELECT * from foo;

The SQL statement is written in the command window;

Instance::::

Create sequence T_auctionarea_sysid_seq

MinValue 1

MaxValue 999999999999

Start with 1

Increment by 1

Cache 20;

Create or Replace Trigger T_auctionarea_sysid

Before insert

On T_auctionarea

For each row

Begin

Select T_auctionarea_sysid_seq.nextval into:new. Sysid from dual;

End

/

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.