Bird
0
0

Consider this SQL procedure snippet:

medium📝 query result Q4 of 15
SQL - Stored Procedures and Functions
Consider this SQL procedure snippet:
DECLARE v_age INT DEFAULT 20;
IF v_age >= 18 THEN
  SET @result = 'Adult';
ELSE
  SET @result = 'Minor';
END IF;

What will be the value of @result after execution?
A'Minor'
BNULL
C'Adult'
DError due to missing ELSE
Step-by-Step Solution
Solution:
  1. Step 1: Check the condition value

    v_age is 20, which is greater than or equal to 18.
  2. Step 2: Determine which block runs

    The IF block runs, setting @result to 'Adult'.
  3. Final Answer:

    'Adult' -> Option C
  4. Quick Check:

    Condition true sets 'Adult' = B [OK]
Quick Trick: Condition true runs IF block, else runs ELSE block [OK]
Common Mistakes:
  • Assuming ELSE runs when condition is true
  • Confusing variable scope

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes