THEN is not a stand-alone statement; it is a clause that appears inside conditional constructs. In Standard SQL it is used in CASE expressions to map each WHEN condition to its corresponding result. Some procedural dialects (PL/pgSQL, T-SQL, PL/SQL, MySQL stored programs) also use THEN in IF … THEN … END IF blocks. The SQL engine evaluates conditions top-down; on the first true WHEN (or IF) it executes or returns the expression following THEN and skips the remaining branches. If no conditions match, control passes to ELSE or raises NULL where ELSE is optional. THEN can return scalars, subqueries, expressions, or execute statement blocks depending on context. Although trivial in appearance, correct use of THEN ensures deterministic branching, readable code, and prevents fall-through errors.
SQL-92
THEN specifies the result or statement block that should run when the associated condition in a CASE or IF construct is true.
No. ELSE is optional, but without it unmatched conditions return NULL or do nothing, which can lead to unexpected results.
Yes. The expression after THEN can be a scalar subquery as long as it returns exactly one value compatible with the CASE result type.
In stored procedures THEN begins a block of one or more statements executed when the IF condition is true, whereas in plain SQL it returns a single expression.