Bird
0
0

Consider this PL/pgSQL snippet:

medium📝 query result Q13 of 15
PostgreSQL - PL/pgSQL Fundamentals
Consider this PL/pgSQL snippet:
DECLARE
  grade CHAR := 'B';
  result TEXT;
BEGIN
  CASE grade
    WHEN 'A' THEN result := 'Excellent';
    WHEN 'B' THEN result := 'Good';
    ELSE result := 'Average';
  END CASE;
  RETURN result;
END;

What will be the returned value?
A'Good'
B'Average'
C'Excellent'
DNULL
Step-by-Step Solution
Solution:
  1. Step 1: Identify the value of grade

    The variable grade is set to 'B'.
  2. Step 2: Match grade in CASE

    CASE checks 'B', matches the second WHEN clause, so result becomes 'Good'.
  3. Final Answer:

    'Good' -> Option A
  4. Quick Check:

    grade 'B' returns 'Good' [OK]
Quick Trick: Match CASE value to WHEN clause for output [OK]
Common Mistakes:
  • Choosing ELSE when a WHEN matches
  • Confusing variable assignment inside CASE
  • Assuming NULL if no ELSE present

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes