Click to See Complete Forum and Search --> : Help writing update trigger..


smallpin
09-03-2002, 09:08 AM
Hi All,
I am trying to write an update trigger for my customer table on my web application. I will like the customerId, first name and last name cloumns to be unchanged but all the other columns on the table to change. I was able to come up with little code but I doubt if it will serve this purpose.

TRIGGER customer_update
BEFORE UPDATE ON CUSTOMER
FOR EACH ROW
DECLARE

v_username VARCHAR(20);

BEGIN
if updating then
select username into v_username from customer;
if :new.username = v_username then
insert into customer (username, customerid, password, firstname, lastname, address1,
address2, city, state, postcode, home_phone, work_phone,fax, mobile_phone, email,
creditcard_num,
card_exp_month, card_exp_year, creditcard_type, school, profile, region )

values

( :old.username, :old.customerid, :new.password, :new.firstname, :new.lastname, :new.address1,
:new.address2, :new.city, :new.state, :new.postcode, :new.home_phone, :new.work_phone, :new.fax,
:new.mobile_phone, :new.email, :new.creditcard_num, :new.card_exp_month, :new.card_exp_year,
:new.creditcard_type, :new.school, :new.profile, :new.region );

-- where :new.username = v_username;
end if;
end if;

EXCEPTION
WHEN OTHERS THEN
NULL ;
END customer_update;

gandolf989
09-03-2002, 12:02 PM
TRIGGER customer_update
BEFORE UPDATE ON CUSTOMER
FOR EACH ROW IS
BEGIN
:NEW.username := :OLD.username;
:NEW.firstname := :OLD.firstname;
:NEW.lastname := :OLD.lastname;
END;
/