Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Sequence generation.
In article <7mn22h$ide$1_at_emu.cs.rmit.edu.au>,
Abhimanyu Parasher <aparashe_at_numbat.cs.rmit.edu.au> wrote:
> Hi!
> Thanks for reading this posting.
> Can anybody explain me how to generate a sequence for a specific
column. For example I want to an id column to be generated automatically
in a sequence (1,2,3,4 i.e. something of sort of AUTOINCREMENT).
>
> I tried to use a trigger for BEFORE INSERT, but was unsuccessful.
>
> Can anybody help ?
>
> Thanks & Regards
>
> Abhimanyu Parasher
Hello
I am not sure why you were unsuccessful with the trigger. Anyway, here
is how I would handle this.
Make a sequence:
Create sequence <sequence_name) start with 1 increment by 1;
(P.S. there are other optional parameters as well)
Now with all the insert statements
insert into <table_name> (PK, COL1, COL2) values
(<sequence_name>.nextval, value1, value2)
If you the insertion of primary key to be transparent, then you can write a trigger, before insert; insert the next_val first, and then update the reamining columns with the incoming values.
Hope it helps
Owais
>
> --
>
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Received on Fri Jul 16 1999 - 10:48:20 CDT
![]() |
![]() |