Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Trigger with sequence

Re: Trigger with sequence

From: david wendelken <davewendelken_at_earthlink.net>
Date: Tue, 17 May 2005 21:27:56 -0700 (PDT)
Message-ID: <19133402.1116390476067.JavaMail.root@rowlf.psp.pas.earthlink.net>


try this:

BEGIN IF INSERTING THEN
   if :new.id is null then

      select myclassseq.nextval into :new.id from dual;    end if;
END IF;           END; sorry, brain is very tired. can't remember whether this would work instead of the select statement above:

:new.id := myclassseq.nextval;

time for me to hit the sack and get that brain working again. :)

It's very important to only supply a value for the id field in the trigger if the value that comes in is null. That way, if you ever need to supply the id value in the insert statement, you can do it. Otherwise, you won't know the pk of the record you just inserted, which can be very awkward when you want to insert some child records in a related table...

--
http://www.freelists.org/webpage/oracle-l
Received on Wed May 18 2005 - 00:35:22 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US