Re: sequence as a not null value in tables

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 6 Jan 2002 12:43:09 -0800
Message-ID: <a1acst02cse_at_drn.newsguy.com>


In article <a1a0sq$n1$1_at_news.onet.pl>, "Rodek" says...
>
>"Rodek" <roderyk_old_at_poczta.onet.pl-nospam> wrote in
>news:a0lbdr$qok$1_at_news.onet.pl:
>
>> Hello
>> Does anybody knows how to use sequence in WebDB?
>> I want to use it when I pushed Insert button on a form.
>
>Create insert before -trigger in database to use the sequence.
>
>-- Harri
>
>Thank Harri very much, trigger was the right.
>I wanted to put sequence in an identification number field, which must be
>not null.
>With "before insert" I didnt solve that problem. I took "after insert" and
>I update table "id" field with sequence in trigger body. First I altered
>table
>by inserting default 0 value of this field.
>Can Anybody write down how to do this with "befor insert" and dont use
>default values in table?
>
>THX
>Rodek
>
>
>
>

create sequence my_seq;

create table t ( x int primary key );

create or replace trigger t_trigger
before insert on t FOR EACH ROW
begin
  select my_seq.nextval into :new.x from dual; end;
/

that'll do it.

--
Thomas Kyte (tkyte_at_us.oracle.com)             http://asktom.oracle.com/ 
Expert one on one Oracle, programming techniques and solutions for Oracle.
http://www.amazon.com/exec/obidos/ASIN/1861004826/  
Opinions are mine and do not necessarily reflect those of Oracle Corp 
Received on Sun Jan 06 2002 - 21:43:09 CET

Original text of this message