Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: sequences as defaults
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
![]() |
![]() |