Call Stored Procedures with OUT and INOUT parameters
masterWhen calling a Stored Procedure (SP) that contains OUT or INOUT parameters:
- Use Parameter Markers: Always use
?markers for the parameters in yourCALLstatement. - Use Objects for Bindings: Pass the parameters as objects to specify the
ParamType(e.g.,OUTPUTorINOUT). - Handling Results: If the Stored Procedure returns result sets, they will be appended to the returned array after the output parameter values.
Result Format: [outValue1, outValue2, resultSet1, resultSet2, ...] where each resultSet is an array of row objects.
// Example pattern for a procedure with 2 OUT params and 1 result set
// Result: [val1, val2, [{col: 'row1'}, {col: 'row2'}]]
conn.query("CALL my_procedure(?, ?)", [ {ParamType: "OUTPUT"}, {ParamType: "INOUT", Data: "input"} ], (err, result) => {
// result contains output values followed by result sets
});