0
0
MySQLquery~10 mins

Procedure parameters (IN, OUT, INOUT) in MySQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Procedure parameters (IN, OUT, INOUT)
Start Procedure Call
Pass IN parameter value
Procedure executes using IN value
Modify OUT and INOUT parameters inside procedure
Return OUT and INOUT values to caller
End Procedure Call
This flow shows how IN parameters are passed in, OUT and INOUT parameters are modified inside the procedure, and then returned to the caller.
Execution Sample
MySQL
CREATE PROCEDURE example_proc(IN in_val INT, OUT out_val INT, INOUT inout_val INT)
BEGIN
  SET out_val = in_val + 10;
  SET inout_val = inout_val + in_val;
END
This procedure takes an IN parameter, modifies OUT and INOUT parameters based on it.
Execution Table
StepParameterInitial ValueActionValue After Action
1in_val5 (passed in)Use as input5
2out_valNULLSet to in_val + 1015
3inout_val3 (passed in)Add in_val to inout_val8
4Procedure ends-Return out_val and inout_val to caller-
💡 Procedure ends after setting OUT and INOUT parameters; values returned to caller.
Variable Tracker
ParameterStartAfter Step 2After Step 3Final
in_val5555
out_valNULL151515
inout_val3388
Key Moments - 3 Insights
Why can't we change the IN parameter inside the procedure?
IN parameters are read-only inside the procedure, so their value stays the same as shown in execution_table step 1.
How do OUT parameters get their value back to the caller?
OUT parameters are assigned inside the procedure (step 2) and their final value is returned after the procedure ends (step 4).
What happens to INOUT parameters during execution?
INOUT parameters start with a value from the caller (step 1), can be read and changed inside the procedure (step 3), and the updated value is returned (step 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of out_val after step 2?
A15
B5
CNULL
D8
💡 Hint
Check the 'Value After Action' column for out_val at step 2 in the execution_table.
At which step does inout_val change its value?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the 'Action' column for inout_val in the execution_table to see when it is modified.
If the initial in_val was 7 instead of 5, what would out_val be after step 2?
A7
B12
C17
DNULL
💡 Hint
out_val is set to in_val + 10 at step 2; check execution_table logic.
Concept Snapshot
Procedure parameters in MySQL:
- IN: input only, cannot be changed inside procedure.
- OUT: output only, set inside procedure and returned.
- INOUT: input and output, can be read and changed.
Use SET inside procedure to assign OUT and INOUT values.
Caller receives OUT and INOUT updated values after execution.
Full Transcript
This visual execution shows how MySQL procedure parameters work. The IN parameter is passed in and used as input without change. The OUT parameter starts null and is assigned a new value inside the procedure. The INOUT parameter starts with a value, is modified inside, and the new value is returned. The execution table tracks each step and parameter value changes. Key moments clarify common confusions about parameter roles. The quiz tests understanding of parameter values at different steps. The snapshot summarizes the behavior of IN, OUT, and INOUT parameters in procedures.