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: Sequence

Re: Sequence

From: DriftWood <drift_wood_at_my-deja.com>
Date: 2000/01/31
Message-ID: <8748jv$kji$1@nnrp1.deja.com>#1/1

In article <8743h2$se4_at_nntpa.cb.lucent.com>,   "Gary Knopp" <gknopp_at_ascend.com> wrote:

>

> Is there away to assign a sequence number in a
> a before insert trigger event? I can't seem to get
> this to work properly.
  1. from SQLPLUS create a sequence:

 create sequence t_seq
   start with 1000
   increment by 1;

2) create the table 't':

  create table t (seq number, col2 number);

  describe t

   Name                            Null?Type
   ------------------------------- -------- ----
   SEQ                              NUMBER
   COL2                             NUMBER




3)Create a trigger to fire before the insert on table 't':

  create or replace trigger trig
  before insert on t
  for each row
  begin
   select t_seq.nextval into :new.seq from dual;   end;

4) Now, when an insert occurs on table 't' this

   trigger 'trig' will automatically get called and will update the    'seq' column with the next value in sequence 't_seq'.

-cheers
  DW



"It is a kind of good deed to say well; and yet words are not deeds.   -William Shakespeare"

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Mon Jan 31 2000 - 00:00:00 CST

Original text of this message

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