Dynamic SQL
Dynamic SQL
CASE
WHEN <condition> then
<statements>
WHEN <condition> then
<statements>
…
ELSE
<statements>
END CASE;
Looping
[begin_label:] LOOP
<statement list>
END LOOP [end_label]
Note that the end_label has to = the begin_label
Both are optional
[begin_label:] REPEAT
<statement list>
UNTIL <search_condition>
END REPEAT [end_label]
Repeat Until Example
DELIMITER //
CREATE FUNCTION CalcIncome ( starting_value INT )
RETURNS INT
BEGIN
DECLARE income INT;
SET income = 0;
label1: REPEAT
SET income = income + starting_value;
UNTIL income >= 4000
END REPEAT label1;
RETURN income;
END; //
DELIMITER ;
Notes on the previous example
61
Roles & Privileges
62