Bird
0
0

How would you modify this procedure to return both the sum and product of two numbers?

hard📝 Application Q9 of 15
SQL - Stored Procedures and Functions
How would you modify this procedure to return both the sum and product of two numbers?
CREATE PROCEDURE calc(IN a INT, IN b INT, OUT sum INT)
BEGIN
SET sum = a + b;
END;
AReturn product using a SELECT statement instead of OUT parameter.
BChange sum parameter to INOUT and calculate product inside.
CAdd another OUT parameter for product and set it inside the procedure.
DUse only IN parameters and calculate product outside the procedure.
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to return multiple values

    Use multiple OUT parameters to return multiple results from a procedure.
  2. Step 2: Apply to given procedure

    Add an OUT parameter for product and assign it inside the procedure body.
  3. Final Answer:

    Add another OUT parameter for product and set it inside the procedure. -> Option C
  4. Quick Check:

    Multiple OUT parameters return multiple values [OK]
Quick Trick: Use multiple OUT parameters for multiple outputs [OK]
Common Mistakes:
  • Trying to return multiple values with one OUT
  • Using INOUT incorrectly for output only
  • Relying on SELECT instead of OUT parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes