Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Trigger with sequence
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-lReceived on Wed May 18 2005 - 00:35:22 CDT
![]() |
![]() |