Re: Trigger do automagically increment a value

From: Jeremy Russell <jrinusa_at_gte.net>
Date: Wed, 29 Jul 1998 20:46:34 GMT
Message-ID: <6po1o9$pgh$2_at_news-1.news.gte.net>


Alexander, check your documentation for the use of Oracle sequences; that will give you a unique and ascending serial number.

When you say it doesn't work, it's more helpful to expand on why it doesn't work - for example, what error message (if any).

JR

Alexander Goller <alexg_at_feedback.de> wrote:

>Hi,
>
>i'm currently faced with Oracle. I made some test table, what i want
>next would be a trigger on insert, that searches for the MAX(NR) value
>in my table, adds 1 and takes this as the NR of the insert that i just
>did. I don't really know about the internals of triggers (sorry again),
>but i'm quite willing to find out (will test with postgres at home).
>
>All i found out yet, is that it should look something like this:
>
>CREATE TRIGGER "TEST_DB".blah
>AFTER INSERT ON "TEST_DB"."mydb";
>
>/* maybe this should be changed to BEFORE INSERT, but i don't really
>understand how it works */
>
>DECLARE i integer;
>BEGIN
> select MAX(NR) into i from TEST_DB.mydb;
> /* so here's what i think it should be like */
> /* NR is the name of the field in my table, that */
> /* should get the incremented value */
> NR = i + 1;
>END;
>
>This doesn't work (of course). But the documentation won't really tell
>me how to do it, or i'm just too stupid too understand all about
>triggers.
>It would be great if someone could give me some hint, so that i can
>investigate further.
>
>bye, alex
>--
>Alex 'decay' Goller
>'If Murphy's Law can go wrong, it will.' -- Silverman's Law
Received on Wed Jul 29 1998 - 22:46:34 CEST

Original text of this message