If/Case/While

chunjakim·2023년 2월 12일
0

MySQL API

목록 보기
10/18

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;

0개의 댓글