Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: A proper FAQ - Wish fulfillment
"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');
-- Niall Litchfield Oracle DBA Audit Commission UKReceived on Mon Mar 10 2003 - 08:29:50 CST