0
0
MySQLquery~20 mins

Procedure parameters (IN, OUT, INOUT) in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Procedure Parameters Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of a procedure with IN and OUT parameters
Consider the following MySQL procedure:
DELIMITER $$
CREATE PROCEDURE CalculateSum(IN a INT, IN b INT, OUT sum_result INT)
BEGIN
  SET sum_result = a + b;
END$$
DELIMITER ;

If you call this procedure with a=5 and b=7, what will be the value of sum_result after execution?
MySQL
CALL CalculateSum(5, 7, @sum_result);
SELECT @sum_result;
A35
B12
CNULL
DError: sum_result is not set
Attempts:
2 left
💡 Hint
OUT parameters are used to return values from procedures.
query_result
intermediate
2:00remaining
Behavior of INOUT parameter in MySQL procedure
Given this procedure:
DELIMITER $$
CREATE PROCEDURE IncrementValue(INOUT val INT)
BEGIN
  SET val = val + 1;
END$$
DELIMITER ;

If you execute:
SET @x = 10;
CALL IncrementValue(@x);
SELECT @x;

What is the output of SELECT @x;?
MySQL
SET @x = 10;
CALL IncrementValue(@x);
SELECT @x;
A11
B10
CNULL
DError: val is not initialized
Attempts:
2 left
💡 Hint
INOUT parameters can be used to pass values in and get updated values out.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in procedure parameter declaration
Which of the following procedure declarations is syntactically correct in MySQL?
ACREATE PROCEDURE TestProc(IN a INT, OUT b INT, INOUT c INT) SET b = a + c; END;
BCREATE PROCEDURE TestProc(a INT IN, b INT OUT, c INT INOUT) BEGIN SET b = a + c; END;
CCREATE PROCEDURE TestProc(IN a INT, OUT b INT, c INT INOUT) BEGIN SET b = a + c; END;
DCREATE PROCEDURE TestProc(IN a INT, OUT b INT, INOUT c INT) BEGIN SET b = a + c; END;
Attempts:
2 left
💡 Hint
Parameter modes come before the data type in MySQL.
🔧 Debug
advanced
2:00remaining
Why does this procedure call fail?
Given the procedure:
DELIMITER $$
CREATE PROCEDURE Multiply(IN x INT, IN y INT, OUT product INT)
BEGIN
  SET product = x * y;
END$$
DELIMITER ;

You run:
CALL Multiply(3, 4, 12);

Why does this call fail?
MySQL
CALL Multiply(3, 4, 12);
ABecause OUT parameters must be passed as variables, not constants
BBecause the procedure requires only two parameters
CBecause the procedure does not have an OUT parameter
DBecause the procedure must be called with named parameters
Attempts:
2 left
💡 Hint
OUT parameters require a variable to store the output value.
🧠 Conceptual
expert
3:00remaining
Effect of IN, OUT, and INOUT parameters on variable values
Suppose you have these variables:
SET @a = 5;
SET @b = 10;
SET @c = 15;

And this procedure:
DELIMITER $$
CREATE PROCEDURE TestParams(IN x INT, OUT y INT, INOUT z INT)
BEGIN
  SET y = x + z;
  SET z = z + 5;
END$$
DELIMITER ;

After executing:
CALL TestParams(@a, @b, @c);
SELECT @a, @b, @c;

What is the output of SELECT @a, @b, @c;?
MySQL
SET @a = 5;
SET @b = 10;
SET @c = 15;
CALL TestParams(@a, @b, @c);
SELECT @a, @b, @c;
A5, 15, 20
B5, 20, 15
C5, 20, 20
D5, 10, 15
Attempts:
2 left
💡 Hint
IN parameters do not change the original variable; OUT and INOUT can update variables.