Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: A proper FAQ - Wish fulfillment
On Mon, 10 Mar 2003 14:29:50 -0000, "Niall Litchfield"
<n-litchfield_at_audit-commission.gov.uk> wrote:
>"Pablo Sanchez" <pablo_at_dev.null> wrote in message
>news:Xns933A463B9B830pingottpingottbah_at_216.166.71.233...
>> "Niall Litchfield" <n-litchfield_at_audit-commission.gov.uk> wrote in
>> news:3e6c9546$0$225$ed9e5944_at_reading.news.pipex.net:
>>
>> > b) There is no autoincrementing datatype in Oracle. You need to create a
>> > sequence and a before insert row level trigger. For example
>> >
>> > create table t(id number,description varchar2(50));
>> >
>> > create sequence seq_t start with 1 increment by 1 cache 50;
>> >
>> > create trigger trg_i_t
>> > before insert on t
>> > for each row
>> > begin
>> > select seq_t.nextval into :new.id from dual;
>> > end;
>> > /
>>
>> - or -
>>
>> -- without using a trigger:
>>
>> INSERT INTO t SELECT seq_t.nextval, 'hola!' FROM DUAL;
>
>
>Good point, and there is of course yet another version (which saves an
>infinitesimal amount of time)
>
>insert into t values(seq_t.nextval,'hola');
Or in SQL*Loader, you can put
column_name sequence(max)
in the control file and it'll auto-insert values in that column, starting at the current max value + 1.
John Received on Mon Mar 10 2003 - 12:34:23 CST