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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Increament

Re: Increament

From: Brian Tkatch <SPAMBLOCK.Maxwell_Smart_at_ThePentagon.com.SPAMBLOCK>
Date: Mon, 29 Oct 2001 03:27:19 GMT
Message-ID: <3bdccb91.1514918250@news.alt.net>


On Mon, 29 Oct 2001 12:02:22 +0800, Oliver Wong <oliverwong_at_aforce.com> wrote:

>How can I create a field that will increament by n?
>Thank you!
>
>
>

Most probably you want to use a SEQUENCE and a TRIGGER.

Check out the CREATE SEQUENCE command. By default it starts at one and increments by one, but you can change both of these.

The CREATE TRIGGER command can create a trigger that will automatically put the number in the column.

An example:

CREATE TABLE MyTable (Id NUMBER PRIMARY KEY);

CREATE SEQUENCE MyTableSEQ NOCACHE ORDER;

CREATE OR REPLACE TRIGGER MyTableANR
BEFORE INSERT ON MyTable
FOR EACH ROW
BEGIN
  SELECT MyTableSEQ.NEXTVAL INTO :NEW.Id FROM Dual; END MyTableANR;
/

Brian Received on Sun Oct 28 2001 - 21:27:19 CST

Original text of this message

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