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

Home -> Community -> Usenet -> c.d.o.server -> Re: Alternatives to Sequences?

Re: Alternatives to Sequences?

From: Kevin P. Fleming <kfleming_at_access-laserpress.com>
Date: Mon, 27 Sep 1999 21:37:28 GMT
Message-ID: <ssRH3.4338$UD4.28524@news.rdc1.az.home.com>


You need to create your sequences, then using BEFORE INSERT triggers on each table to populate the primary key columns. The triggers are very simple:

  1. Table named FOO.
  2. Sequence named FOO_SEQUENCE.

CREATE TRIGGER FOO_INSERT
BEFORE INSERT ON TABLE FOO
BEGIN
  :new.keycolumn := FOO_SEQUENCE.NEXTVAL; END FOO_INSERT; <cspeer_at_my-deja.com> wrote in message news:7somf8$tfk$1_at_nnrp1.deja.com...
> Hello everyone,
>
> We purchased a software program that ties into an Oracle database.
> We noticed that there are no primary/unique keys on the tables. We are
> adding an auto-incrementing field... And herein the problem lies:
>
> In order to do an insert with an auto-incrementing field, you
> would normally create a sequence and then reference it in your INSERT
> INTO clause. However, we do not have that option since we cannot
> rewrite the code of the software that creates the statement. (We have
> dutifully cursed them and they are working on fixing it.)
>
> What alternatives do we have to do auto-incrementation. I heard
> from the software company, that you can create a field-type that
> increments in Oracle, but a) I don't belive it and b) I have not found
> any reference to it anywhere in documentation.
>
> So is there a field type in Oracle (even non-standard) that I can
> use to auto-increment?
>
> I am beginning to think that I will have to write a Trigger/Stored
> Procedure that will accomplish this. (ie, on insert, update the auto-
> incrementing field with max+1).
>
> References to articles would greatly help (especially if there is
> a reference on writing the trigger.)
>
> Thank you!
>
> CW Speer
> Oracle DBA (Newbie!)
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
Received on Mon Sep 27 1999 - 16:37:28 CDT

Original text of this message

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