Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Newbie: datatype, sequence
create your table (use NUMBER instead of integer)
create a sequence to generate numbers for you.
add a trigger to the table to populate your NUMBER field with a sequence before insert.
create table test (key number, some_data varchar2(50))
/
create sequence seq_test_key start with 1 increment by 1
/
create trigger tr_test_key
before insert on TEST
for each row
begin
if :new.key is null then
select seq_test_key.nextval into :new.key from dual;
end if;
end;
/
"Stefan Lintner" <stefan.lintner_at_wu-wien.ac.at> wrote in message
news:ajd798$ge3$1_at_bird.wu-wien.ac.at...
> Hi,
>
> I am new to Oracle9i SQL and have a problem in choosing the correct
> datatype; I create the following table:
>
> create table test (
> id integer primary key,
> name char(30),
> adress char(40)
> );
>
> Now I would like to have "id" as a sequence. Which datatype should I use
> when I create the table? Integer like in my example above?
>
> Thanks for your help,
> Stefan
>
>
Received on Mon Aug 19 2002 - 17:34:50 CDT