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

Home -> Community -> Usenet -> c.d.o.tools -> Re: sequences as defaults

Re: sequences as defaults

From: Jim Harrison <jim_at_colway.freeserve.co.uk>
Date: 2000/04/21
Message-ID: <8dqj5r$skm$1@newsg4.svr.pol.co.uk>#1/1

You could always use a 'before insert' trigger to set your next value. For example:

CREATE TABLE test_seq_tab
(id NUMBER NOT NULL
,data_col VARCHAR2(10));

create sequence test_seq; -- set your options as you wish

create or replace trigger bef_ins_test_seq_tab before insert on test_seq_tab
for each row
DECLARE
  next_id NUMBER;
BEGIN
  select test_seq.nextval
  into next_id
  from dual;
  :new.id := next_id;
END;
/

insert into test_seq_tab (data_col) values ('xxx');
insert into test_seq_tab (data_col) values ('yyy');
insert into test_seq_tab (data_col) values ('zzz');

Should come up with the values:

1 xxx
2 yyy
3 zzz
etc.

Jim Harrison
Colway Software & Design
www.colway.freeserve.co.uk Received on Fri Apr 21 2000 - 00:00:00 CDT

Original text of this message

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