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: Chris Hamilton <toneczar_at_erols.com>
Date: Wed, 15 Jul 1998 13:49:58 GMT
Message-ID: <6oic62$ej9$1@goo.nwd.usace.army.mil>


"John Bester" <johnb_at_iconnect.co.za> wrote:
>Hi,
>
>I need an example on how to use a SEQUENCE. (Actually, the sequence is not
>so difficult - my problem is the trigger) What I want to do is to set an ID
>column to the next value in a sequence in an (BEFORE?) INSERT trigger.

Assuming you've created a sequence called seq_empno and you want to populate the empno column of the emp table:

create or replace trigger emp_bi
  before insert
  on emp
  for each row
  when new.empno is null
begin
  select seq_empno.nextval
  into :new.empno
  from dual;
end;
/

Chris



Chris Hamilton, DBA
US Army Corps of Engineers
christopher.h.hamilton_at_usace.army.mil
http://www.serve.com/cowpb/chamilton.html Received on Wed Jul 15 1998 - 08:49:58 CDT

Original text of this message

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