OUT
parameters and "results" from stored procedures are two unrelated things.
If you want one or more result sets returned to a client by a stored procedure, you simply use a SELECT
statement in the body of the procedure, and whatever you SELECT
, whether it's a variable, or a string or numeric literal, is returned to the client.
SELECT NOW() AS the_current_time; -- do this inside the stored procedure
This will return the current time from the system clock to the client calling the stored procedure, as a "column" called "the_current_time" ...
OUT
parameters declare variables within the procedure, whose value is set back into the variable you used in that position when you called the procedure, when the procedure finishes.
DELIMITER $$
CREATE PROCEDURE get_the_time (OUT foo DATETIME)
BEGIN
SET foo = NOW();
END $$
DELIMITER ;
...then, call the procedure with a user-defined variable.
CALL get_the_time(@bar);
Subsequently, you'll find that the value that existed inside the procedure in the variable "foo" has been assigned to the variable @bar.
SELECT @bar;
To capture output parameter values, you have to fill the placeholders with variables when you call the procedure, which is why you're getting the N+1 error... you aren't filling the placeholders.
The difference between IN
, OUT
, and INOUT
variables is this:
An IN
variable, if passed in from a user defined variable or a stored program variable (when calling one stored procedure from another stored program) does not modify the original value. For IN
parameters, you can also use literals as arguments.
An OUT
variable returns the last value from the variable inside the procedure, to the variable used in that positional slot when the procedure is called. Inside the procedure, the former value of the variable is not available.
An INOUT
variable passes a value in, and the final value of the internal variable gets set back into the external variable.
Since OUT
and INOUT
can change the value of the variable used to call the procedure, you can't use literals in those slots, when calling a procedure, since, obviously enough, the value of a literal can never be modified within the body of the procedure.
If IN
, OUT
, or INOUT
isn't specified, IN
is assumed.