Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to: Databricks SQL
Databricks Runtime 16.3 and above
Important
This feature is in Public Preview.
Executes lists of statements based on the first condition that evaluates to true.
This statement may only be used within a compound statement.
IF condition THEN { stmt ; } [...]
[ { ELSEIF condition THEN { stmt ; } [...] } [...] ]
[ ELSE { elseStmt ; } [...] ]
END IF
condition
Any expression evaluating to a BOOLEAN.
stmt
A SQL statement to execute if the
condition
istrue
.elseStmt
A SQL statement to execute if no
condition
istrue
. That is allcondition
arefalse
ornull
.
> BEGIN
DECLARE choice DOUBLE DEFAULT 3.9;
DECLARE result STRING;
IF choice < 2 THEN
VALUES ('one fish');
ELSEIF choice < 3 THEN
VALUES ('two fish');
ELSEIF choice < 4 THEN
VALUES ('red fish');
ELSEIF choice < 5 OR choice IS NULL THEN
VALUES ('blue fish');
ELSE
VALUES ('no fish');
END IF;
END;
red fish