|
-
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
( ld.username, ld.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;
God Bless
-
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;
/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|