Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: automatic attribute insert
In article <9bmgne$2q0si$1_at_reader03.wxs.nl>, Loki <rinze_cats_at_hotmail.com>
writes:
>Hiya, I maintain a logtable where the primary key should be a system
>generated (sequential) number.
>
>How do I tell oracle8 to automatically insert this value?
>
>many thanx
>rinze
>
See the SQL Manual and look up create sequence. To use the sequence you have
two choices. First you can code the sequence in the insert statement as in
insert into x (key, col2) values (sequence_name.nextval,'TWO');
Or you can place a before insert trigger on the table and do something like
v_key number;
begin
select sequence_name.nextval into v_key from dual;
:new.key := v_key;
end;