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: Autoincrement functionality

Re: Autoincrement functionality

From: Andreas Jung <ajung_at_sz-sb.de>
Date: Wed, 2 Aug 2000 06:50:34 +0200
Message-Id: <10576.113552@fatcity.com>


On Tue, Aug 01, 2000 at 10:56:14AM -0800, Dave Morgan wrote:
> Hi All,
> I am porting a schema to Oracle from mysql that uses
> AUTOINCREMENT to produce the primary key.
>
> In order to keep the application code the same I have
> to get a number from a sequence and insert into the primary key
> column at the database level.
>
> The only way I have figured out is to use a before insert trigger
> something like:
>
> WARNING: THIS IS UNTESTED PSUEDO CODE
>
> CREATE TRIGGER AUTOINCREMENT
> BEFORE INSERT ON TABLE TEST
> FOR EACH ROW
> BEGIN
> :new.PRIMARY_KEY_ROW = TEST_NUM.nextval;
> END;
You should create a SEQUENCE. You can obtain a unique auto incrementing value by using SEQNAME.NEXTVAL:

create sequence myseq;
insert into mytab (myprimkey,...) values(myseq.nextval,....) Received on Tue Aug 01 2000 - 23:50:34 CDT

Original text of this message

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