Stored procedures in MySQL support three parameter modes: IN, OUT, and INOUT. Understanding these modes is essential for designing flexible and reusable procedures.
Parameter Modes
- IN: The default mode. The caller passes a value in; the procedure can read it but changes are not reflected outside.
- OUT: The procedure writes a value that the caller can read after the call. The initial value seen inside the procedure is NULL.
- INOUT: The caller passes a value in, the procedure can modify it, and the modified value is available to the caller after the call.
Using OUT Parameters
OUT parameters are useful when a procedure needs to return one or more scalar values to the caller without using a result set. You read them using a user-defined variable prefixed with @.