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
/