0
0
SQLquery~20 mins

CREATE PROCEDURE syntax in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stored Procedure Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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;
ASumResult = 15
BNo output, procedure does not return values
CSyntax error due to missing RETURN statement
DSumResult = 8
Attempts:
2 left
💡 Hint
The procedure uses SELECT to output the sum of the two input numbers.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in procedure creation
Which option contains a syntax error when creating a stored procedure in SQL?
ACREATE PROCEDURE TestProc BEGIN SELECT 1; END;
B;DNE ;1 TCELES NIGEB )(corPtseT ERUDECORP ETAERC
CREATE PROCEDURE TestProc() BEGIN SELECT 1; END;
DCREATE PROCEDURE TestProc() BEGIN SELECT 1; END;
Attempts:
2 left
💡 Hint
Check if parentheses are required after procedure name.
🧠 Conceptual
advanced
2:00remaining
Understanding parameter modes in CREATE PROCEDURE
Which parameter mode allows a stored procedure to return a value back to the caller?
AINOUT
BRETURN
COUT
DIN
Attempts:
2 left
💡 Hint
Think about how data flows from procedure to caller.
🔧 Debug
advanced
2: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;
AMissing semicolon after SET statement
BDECLARE cannot be used inside procedures
CSELECT cannot be used inside procedures
DProcedure must have RETURNS clause
Attempts:
2 left
💡 Hint
Check statement terminators inside the procedure body.
optimization
expert
3: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;
AReplace WHILE loop with a recursive procedure call
BCache previously computed factorials in a table and reuse them
CUse a temporary table to store intermediate factorial values
DIncrease the size of the OUT parameter to BIGINT
Attempts:
2 left
💡 Hint
Think about avoiding repeated calculations for the same inputs.