Bird
0
0

Identify the error in this PL/pgSQL snippet:

medium📝 Debug Q7 of 15
PostgreSQL - PL/pgSQL Fundamentals

Identify the error in this PL/pgSQL snippet:

DO $$
DECLARE
  n INT := 3;
BEGIN
  IF n = 1 THEN
    RAISE NOTICE 'One';
  ELSIF n = 2 THEN
    RAISE NOTICE 'Two';
  ELSE
    RAISE NOTICE 'Other'
  END IF;
END $$;
AIncorrect use of ELSIF instead of ELSEIF.
BMissing semicolon after the last RAISE NOTICE statement.
CVariable n is not declared properly.
DMissing END DO statement.
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of RAISE NOTICE statements

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

    The last RAISE NOTICE 'Other' lacks a semicolon.
  3. Final Answer:

    Missing semicolon after the last RAISE NOTICE statement. -> Option B
  4. Quick Check:

    Statements must end with semicolons [OK]
Quick Trick: Every statement ends with semicolon in PL/pgSQL [OK]
Common Mistakes:
  • Using ELSEIF instead of ELSIF
  • Forgetting semicolons after statements
  • Misdeclaring variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes