Declaration/Initializaion
DECLARE <variable> <type>; -- declaration
SET <variable> = <value>; -- set variable
SELECT <column> INTO <variable>
FROM <table>
WHERE <condition>; -- set variable using table
If Statement
IF <condition> THEN
<statement>;
ELSEIF <condition> THEN
<statement>;
ELSE
<statement>;
END IF;
Case Statement
CASE
WHEN <condition> THEN
SET <variable> = <value>;
WHEN <condition> THEN
SET <variable> = <value>;
WHEN <condition> THEN
SET <variable> = <value>;
WHEN <condition> THEN
SET <variable> = <value>;
ELSE
SET <variable> = <value>;
END CASE;
While Loop
<loop>:
WHILE <condition> DO
<statement>; -- ITERATE <loop> : continue, loop 제외 가능
-- LEAVE <loop> : break, loop 제외 가능
END WHILE;