Re: Automatic primary key in Oracle
Date: 1996/01/19
Message-ID: <4doirl$1b1s_at_huey.cadvision.com>#1/1
Veikko V{{t{j{ TKKK (vvaataja_at_news.abo.fi) wrote:
: How to use the oracle sequence feature? I want to use it for an auto
: increment primary key field but I can't figure out how to do it. If I'm
: doing something totally wrong, tell me! This is what I do:
: First I create the sequence with CREATE SEQUENCE SEQ_PRKEY;. Then I
: create a table that uses that key with CREATE TABLE SOMETABLE (ID INTEGER
: NOT NULL, SOMEFIELD VARCHAR(10),...,PRIMARY KEY(ID)); Oracle manuals say
: clearly that I can't use sequences in default values, so I figure that I need
: a trigger to put the sequence number in a record records primary key field.
: But how do I get the sequence number in a PL/SQL trigger??? Oracle doesn't
: accept NEW.ID:=SEQ_PRKEY.NEXTVAL; in the trigger body. WHY?
: Only thing that I want to do is to have an totally automatic primary key
: field. In interbase it works just like I describe above. How do I do it in
: Oracle???
SELECT seq_prkey.nextval into new.id from dual;
-- Names: Bill Beaton beatonb_at_cadvision.com Bill_Beaton_at_calgary.qc-data.com Phone: (403) 295-3254 (Home) (403) 266-8622 (work)Received on Fri Jan 19 1996 - 00:00:00 CET