Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Clarification of 'Sequences'
it would be:
create sequence my_seq;
create table T ( x int primary key, ... );
create trigger t_bifer before insert on T
for each row
begin
select my_seq.nextval into :new.x from dual;
end;
/
A copy of this was sent to "steve hendrikse" <shend_at_sar-net.com> (if that email address didn't require changing) On Wed, 30 Sep 1998 10:08:18 -0400, you wrote:
>Good Day,
>
>I have reasonable experience with both PostgreSQL and Micrsoft SQLServer.
>WIth both I can create a column in a table that automatically generates a
>unique count value. That is:
>
>in MSSQL, i do:
> create tabel test1(
> id int identity(1,1) not null,
> value varchar(80)
> );
>
>in PostgreSQL, it is slightly more complex, but similar to:
>
> create sequence seq_id start 1 increment 1;
> create table test2(
> id int4 default nextval('seq_id') not null,
> value varchar(80)
> );
>
>now, in Oracle 8.0.4 (on Solaris), i believe that i must do something
>similar to the PostgreSQL case. I start with:
>
> create sequence seq_id start with 1 increment by 1;
>
>and then (?????)
>
> create table
>
> id int default seq_id.nextval not null,
> value varchar(80)
> );
>
>but this gets me an error saying that i cannot include a column name
>(seq_id) in the table definition.
>
>now, i conclude that if both MSSQL and PostgreSQL can do this (as shown
>above) there has to be a 'graceful' way to get Oracle to do it also.
>
>please help!!!
>
>thanks in advance,
>steve
>
>
>
Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA
-- http://govt.us.oracle.com/ -- downloadable utilities ---------------------------------------------------------------------------- Opinions are mine and do not necessarily reflect those of Oracle Corporation Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it.Received on Wed Sep 30 1998 - 00:00:00 CDT