Bird
0
0

What is wrong with this CASE statement?

medium📝 Debug Q7 of 15
PostgreSQL - PL/pgSQL Fundamentals
What is wrong with this CASE statement?
DECLARE
  val INT := 3;
  res TEXT;
BEGIN
  CASE
    WHEN val = 1 THEN res := 'One';
    WHEN val = 2 THEN res := 'Two';
    ELSE res := 'Other';
END CASE;
END;
AVariable val is not initialized
BCASE must have an expression after it
CELSE clause is not allowed
DMissing semicolon after ELSE assignment
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of assignments

    Each assignment must end with a semicolon.
  2. Step 2: Identify missing semicolon

    After ELSE res := 'Other' there is no semicolon, causing error.
  3. Final Answer:

    Missing semicolon after ELSE assignment -> Option D
  4. Quick Check:

    Semicolons required after each assignment [OK]
Quick Trick: Every assignment inside CASE needs a semicolon [OK]
Common Mistakes:
  • Omitting semicolon after ELSE
  • Thinking CASE needs expression always
  • Confusing ELSE clause usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes