Re: Help on SQL

From: Joost Ouwerkerk <owrkrj_at_mailhub.sickkids.on.ca>
Date: Mon, 04 May 1998 19:19:32 GMT
Message-ID: <354e12bd.16952491_at_resunix.sickkids.on.ca>


On 4 May 1998 16:18:04 GMT, mehesh_at_bmerhcb1.ca.nortel.com (Mahesh Menon) wrote:

> i'd like to add another tuple with name = 'MENON'
> and category = 'DOS'. the sitno field should be
> generated automatically and should be MAX(SITNO) + 1.

If this is a standard operation, you'd be best off using a SEQUENCE. A sequence is an Oracle object that provides a unique sequential number when requested; like taking a number at the bakery.

CREATE SEQUENCE seq_sitno
INCREMENT BY 1
START WITH 500; Now each time you create a new row (or tuple), you can request the next number from the sequence using NEXTVAL:

INSERT INTO sit_table (sitno,name,category) VALUES (seq_sitno.NEXTVAL,'MENON','DOS');

[Quoted] The current value of the sequence is automatically incremented each time NEXTVAL is called for that sequence. Rolling back the transaction will restore the sequence.

Hope this helps,

Joost Ouwerkerk
Toronto, Canada. Received on Mon May 04 1998 - 21:19:32 CEST

Original text of this message