Challenge - 5 Problems
Parameter Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of a procedure with IN and OUT parameters
Consider the following SQL procedure that takes an IN parameter and an OUT parameter. What will be the value of the OUT parameter after execution?
Procedure:
CREATE PROCEDURE CalculateSquare(IN input_num INT, OUT output_num INT)
BEGIN
SET output_num = input_num * input_num;
END;
Call:
CALL CalculateSquare(4, @result);
SELECT @result;
Procedure:
CREATE PROCEDURE CalculateSquare(IN input_num INT, OUT output_num INT)
BEGIN
SET output_num = input_num * input_num;
END;
Call:
CALL CalculateSquare(4, @result);
SELECT @result;
SQL
CREATE PROCEDURE CalculateSquare(IN input_num INT, OUT output_num INT) BEGIN SET output_num = input_num * input_num; END; CALL CalculateSquare(4, @result); SELECT @result;
Attempts:
2 left
💡 Hint
Remember that the OUT parameter is assigned inside the procedure.
✗ Incorrect
The procedure calculates the square of the input number (4 * 4) and assigns it to the OUT parameter, so the result is 16.
❓ query_result
intermediate2:00remaining
Effect of INOUT parameter modification inside procedure
Given the procedure below, what will be the value of the variable @val after calling the procedure?
Procedure:
CREATE PROCEDURE IncrementValue(INOUT val INT)
BEGIN
SET val = val + 10;
END;
Call:
SET @val = 5;
CALL IncrementValue(@val);
SELECT @val;
Procedure:
CREATE PROCEDURE IncrementValue(INOUT val INT)
BEGIN
SET val = val + 10;
END;
Call:
SET @val = 5;
CALL IncrementValue(@val);
SELECT @val;
SQL
CREATE PROCEDURE IncrementValue(INOUT val INT) BEGIN SET val = val + 10; END; SET @val = 5; CALL IncrementValue(@val); SELECT @val;
Attempts:
2 left
💡 Hint
INOUT parameters can be changed inside the procedure and the change is reflected outside.
✗ Incorrect
The procedure adds 10 to the input value 5, so the final value of @val is 15.
📝 Syntax
advanced2:00remaining
Identify the syntax error in procedure parameter declaration
Which option contains a syntax error in the declaration of procedure parameters?
Attempts:
2 left
💡 Hint
Parameters must specify mode: IN, OUT, or INOUT unless default is IN.
✗ Incorrect
Option D omits the parameter mode keywords (IN, OUT, INOUT), which is invalid syntax in many SQL dialects requiring explicit mode.
🧠 Conceptual
advanced2:00remaining
Understanding parameter modes in stored procedures
Which statement correctly describes the behavior of IN, OUT, and INOUT parameters in stored procedures?
Attempts:
2 left
💡 Hint
Think about which parameters are used to send data back to the caller.
✗ Incorrect
OUT parameters are used to return values from the procedure and must be assigned inside it. IN parameters are read-only, and INOUT parameters can be read and modified.
🔧 Debug
expert2:00remaining
Why does this procedure call fail?
Given the procedure and call below, why does the call fail?
Procedure:
CREATE PROCEDURE UpdateValue(INOUT val INT)
BEGIN
SET val = val * 2;
END;
Call:
CALL UpdateValue(10);
Procedure:
CREATE PROCEDURE UpdateValue(INOUT val INT)
BEGIN
SET val = val * 2;
END;
Call:
CALL UpdateValue(10);
SQL
CREATE PROCEDURE UpdateValue(INOUT val INT) BEGIN SET val = val * 2; END; CALL UpdateValue(10);
Attempts:
2 left
💡 Hint
Consider what kind of argument can be passed to an INOUT parameter.
✗ Incorrect
INOUT parameters require a variable to hold the value because the procedure can modify it. Passing a constant like 10 is invalid and causes an error.