Re: Trigger with sequence

  • From: david wendelken <davewendelken@xxxxxxxxxxxxx>
  • To: oracle-l@xxxxxxxxxxxxx
  • Date: Tue, 17 May 2005 21:27:56 -0700 (PDT)

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...


--
//www.freelists.org/webpage/oracle-l

Other related posts: