Re: Trigger Question

From: Jerry Davidson <jerry_davidson_at_compuserve.com>
Date: Fri, 22 Mar 2002 14:12:21 -0600
Message-ID: <3C9B9025.9040603_at_compuserve.com>


Me

>>=============================================================
>>CREATE OR REPLACE TRIGGER USA_Contractor_BI
>> BEFORE INSERT
>> ON USA_Contractor
>> FOR EACH ROW
>> WHEN (:old.contractor_id IS NULL)
>>declare
>> newid number;
>> begin
>> select USA_Contractor_seq.nextval
>> into newid from dual;
>>
>> :new.Contractor_Key := newid;
>> :new.Contractor_ID := 'CID' || LPAD(TO_CHAR(newid), 5, '0');
>> :new.Create_Date := sysdate;
>>END USA_Contractor_BI;
>>==============================================================

You:

> You can't check for :old on an insert. :old.* will always be null on an 
> insert. You should be checking WHEN (:new.contractor_id IS NULL).
> If the record being inserted already has a contractor_id then the trigger 
> will not fire. 


Thank you. I included the above example because I made a mistake in it when I said: "WHEN (:old...." because you don't use the ":" in this section.

Your correction was what I needed to get it to work! Received on Fri Mar 22 2002 - 21:12:21 CET

Original text of this message