I want to create a trigger TR_rate, that checks a "features" field on new rows as they are inserted and adjusts a rate based on the features included.
The features field can contain multiple values, and I want the condition to apply for each value. So if the field contains 'Feature1, Feature2', the rate should go up by 35.
My current code approach only works if there is one feature. How can I rewrite it to accomodate for multiple features?
CREATE OR REPLACE TRIGGER TR_rate
BEFORE INSERT
ON rates_table
FOR EACH ROW
BEGIN
IF(:NEW.features = 'Feature1') THEN
:NEW.rate := (:NEW.rate + 15);
IF(:NEW.features = 'Feature2') THEN
:NEW.rate := (:NEW.rate + 20);
IF(:NEW.features = 'Feature3') THEN
:NEW.rate := (:NEW.rate + 30);
END IF;
END IF;
END IF;
END;
/
rates_tableto features (i.e.rate_feature). You could then iterate through the features associated with a particular rate.