In the example below, if shoe_count has a value of 10, both the first and second Boolean expressions yield TRUE. Nevertheless, order_quantity is assigned the proper value of 50 because processing of an IF statement stops after an expression yields TRUE and its associated sequence of statements is executed. The expression associated with ELSIF is never evaluated and control passes to the INSERT statement.
IF shoe_count < 20 THEN
order_quantity := 50;
ELSIF shoe_count < 30 THEN
order_quantity := 20;
ELSE
order_quantity := 10;
END IF;
INSERT INTO purchase_order VALUES (shoe_type, order_quantity);
In the following example, depending on the value of score, one of two status messages is inserted into the grades table:
IF score < 70 THEN
fail := fail + 1;
INSERT INTO grades VALUES (student_id, 'Failed');
ELSE
pass := pass + 1;
INSERT INTO grades VALUES (student_id, 'Passed');
END IF;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.