Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Table autonumber field

RE: Table autonumber field

From: Jacques Kilchoer <Jacques.Kilchoer_at_quest.com>
Date: Tue, 08 May 2001 20:31:12 -0700
Message-ID: <F001.002FD6A1.20010508201022@fatcity.com>

> -----Original Message-----
> From: Mike T [mailto:mtmind_at_the-beach.net]
>
> I need to create an autonumber field in an Oracle Table (from
> a SQL server table identity field) , I was looking for a
> default value that I could assign (select max(ID) + 1)  or
> some way to create an identity field
> or use a trigger after insert but nothing seems to work for
> me. Any help would be appreciated, This field also has to be
> the primary Key .

Read the Oracle SQL manual about the use of sequences and triggers. Here's an example: SQL> create sequence s ;

Sequence created.

SQL> create table t (id number primary key, name varchar2 (30)) ;

Table created.

SQL> create trigger b4it

  2  before insert on t
  3  for each row
  4  begin
  5     select s.nextval into :new.id from dual ;
  6  end ;
  7  /


Trigger created.

SQL> insert into t (name) values ('Mao Chu') ;

1 row created.

SQL> insert into t (name) values ('Mohandas Gandhi') ;

1 row created.

SQL> commit ;

Commit complete.

SQL> select * from t ;

        ID NAME

---------- ------------------------------
         1 Mao Chu
         2 Mohandas Gandhi

Jacques R. Kilchoer
(949) 754-8816
Quest Software, Inc.
8001 Irvine Center Drive
Irvine, California 92618
U.S.A.
http://www.quest.com Received on Tue May 08 2001 - 22:31:12 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US