Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Auto Sequencing When Insert
A copy of this was sent to "Kenneth Xu" <xu_dong_at_irel.com.sg>
(if that email address didn't require changing)
On Fri, 10 Jul 1998 17:53:43 +0800, you wrote:
>Hi all,
>
>We used to be Informix users before and new to Oracle.
>
>We used serial data type in Informix to generate the auto sequencing number,
>application do need to specify a value for such a field when inserting a
>record to database.
>
>Now we want to change the database engine to Oracle but cannot find a match.
>We know Oracle provides a sequence object which can do the similar job, so
>we use a trigger to simulate that behave.
>
>Unfortunately, We encountered the compilation error with following code:
>
>
>---------------------------------
>create table TestTable(
> UserID number(9),
> Name char(50)
>);
>
>create sequence TestSeq;
>
>create trigger Test_BeforeInsert
>before insert on TestTable for each row
>begin
> if :new.UserID is null then
> :new.UserID := TestSeq.nextval;
select testseq.nextval into :new.userid from dual;
> end if;
>end;
>------------------------------
>
You need to SELECT sequences (they are database objects -- you need to go to the server to get them...)
>
>It is very much appreciated if somebody point me a direction.
>
>TIA,
>
>Ken.
>
Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA
http://govt.us.oracle.com/ -- downloadable utilities
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 Fri Jul 10 1998 - 10:22:01 CDT
![]() |
![]() |