Tuesday, August 3, 2010

use of trigger for updating a column

CREATE OR REPLACE TRIGGER isrert_bill BEFORE INSERT OR UPDATE ON system.bill
FOR EACH ROW
BEGIN 
IF :NEW.unit=0 THEN
:NEW.bill:=0;
elsif :new.unit>0 and :new.unit<100 then
:NEW.bill:=:NEW.unit*2.5;
elsif :new.unit>=100 and :new.unit<250 then
:new.bill:=:NEW.unit*3;
elsif :NEW.unit>=250 and :NEW.unit<500 then
:NEW.bill:=:NEW.unit*4.5;
else
:NEW.bill:=:NEW.unit*6;
END IF;
END;
/


--it will update a column of no values named bill calculating the unit column


Enjoy SQL.. 

No comments:

Post a Comment