Challenge - 5 Problems
Stored Procedure Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of a simple stored procedure call
Consider the following stored procedure in SQL that returns the sum of two numbers. What will be the output when calling
CALL AddNumbers(3, 5);?SQL
CREATE PROCEDURE AddNumbers(IN num1 INT, IN num2 INT) BEGIN SELECT num1 + num2 AS SumResult; END;
Attempts:
2 left
💡 Hint
The procedure uses SELECT to output the sum of the two input numbers.
✗ Incorrect
The procedure takes two input integers and uses SELECT to output their sum as SumResult. Calling with 3 and 5 returns 8.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in procedure creation
Which option contains a syntax error when creating a stored procedure in SQL?
Attempts:
2 left
💡 Hint
Check if parentheses are required after procedure name.
✗ Incorrect
In SQL, parentheses are required after the procedure name even if there are no parameters. Option A misses the parentheses, causing syntax error.
🧠 Conceptual
advanced2:00remaining
Understanding parameter modes in CREATE PROCEDURE
Which parameter mode allows a stored procedure to return a value back to the caller?
Attempts:
2 left
💡 Hint
Think about how data flows from procedure to caller.
✗ Incorrect
The OUT parameter mode allows the procedure to send a value back to the caller. IN is input only, INOUT is input and output, RETURN is not a parameter mode.
🔧 Debug
advanced2:00remaining
Why does this procedure fail to compile?
Given the procedure below, why does it fail to compile?
CREATE PROCEDURE MultiplyNumbers(IN a INT, IN b INT)
BEGIN
DECLARE result INT;
SET result = a * b
SELECT result;
END;
SQL
CREATE PROCEDURE MultiplyNumbers(IN a INT, IN b INT) BEGIN DECLARE result INT; SET result = a * b; SELECT result; END;
Attempts:
2 left
💡 Hint
Check statement terminators inside the procedure body.
✗ Incorrect
Each statement inside the procedure must end with a semicolon. The SET statement is missing a semicolon, causing a syntax error.
❓ optimization
expert3:00remaining
Optimizing procedure for multiple calls
You have a procedure that calculates the factorial of a number using a loop. Which change will improve performance when calling it many times?
SQL
CREATE PROCEDURE Factorial(IN n INT, OUT fact BIGINT) BEGIN SET fact = 1; DECLARE i INT DEFAULT 1; WHILE i <= n DO SET fact = fact * i; SET i = i + 1; END WHILE; END;
Attempts:
2 left
💡 Hint
Think about avoiding repeated calculations for the same inputs.
✗ Incorrect
Caching previously computed factorials avoids recalculating them, improving performance for multiple calls with overlapping inputs.