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: How to imitate autovalues ?

Re: How to imitate autovalues ?

From: Jonathan Gennick <gennick_at_worldnet.att.net>
Date: Sat, 09 May 1998 00:58:45 GMT
Message-ID: <6j09o1$5gu@bgtnsc01.worldnet.att.net>


On Thu, 07 May 1998 16:59:47 +0200, Thorsten Buchheim <buchheim_at_ls7.uni.dortmund.de> wrote:

>Unfortunately I´m a newbie in ORACLE (guessed it?) and presumably
>this can be done by a TRIGGER. If I only knew how....
>It would be nice if you could give me with some hints how to do it.

You need a trigger like this:

CREATE OR REPLACE TRIGGER assign_a_key BEFORE INSERT ON your_table
FOR EACH ROW
AS

   next_key_val NUMBER;
BEGIN
   SELECT your_sequence.NEXTVAL into next_key_val FROM dual;    :new.your_key := next_key_val;
END;
/

Before creating the trigger, you will need to create a sequence. You can do that with this command:

        CREATE SEQUENCE your_sequence;

There are a number of options that can be used with CREATE SEQUENCE, you should read up on them.

Jonathan Received on Fri May 08 1998 - 19:58:45 CDT

Original text of this message

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