Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How do I have sequence automatically insert on record insertion
Use When-Create-Record trigger at block level. Basic commands are:
DECLARE
SEQ_ID NUMBER;
BEGIN
SELECT SEQUENCENAME.NEXTVAL INTO SEQ_ID FROM DUAL;
:BLOCKNAME.ID := SEQ_ID;
END;
Send me a message if you need more details.
Brian Lavender wrote:
> I have a table that I want a sequence automatically inserted as the key value
> when a record is inserted into it.
>
> I have the following table:
>
> parent
> ---------------
> PARENTID * NUMBER
> FIRST VARCHAR2(8)
> LAST VARCHAR2(8)
> SEX VARCHAR2 (1)
>
> * - UNIQUE FIELD
>
> I created a sequence.
>
> create sequence FOO increment by 1 start with 100;
>
> I can insert a record into the table with the sql statement and it will insert
> the next value from the sequence into the table:
>
> insert into parent (PARENTID, FIRST, LAST, SEX) VALUES
> (FOO.NextVal, 'BILL','BAKER','M');
>
> Is there a way I can create a trigger which will automatically insert the FOO
> value from the sequence when I perform the insert below?
>
> insert into parent (FIRST, LAST, SEX) VALUES ('MARY','SMITHY','F');
>
> brian
> -----------------
> Brian E. Lavender
> US Army Corps of Engineers -- Programmer / Systems Analyst
> Sacramento, CA (916) 557-6623
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Received on Thu Apr 08 1999 - 14:51:02 CDT
![]() |
![]() |