I have a mysql stored procedure from this (google book), and one example is this:
DELIMITER $$ DROP PROCEDURE IF EXISTS my_sqrt$$ CREATE PROCEDURE my_sqrt(input_number INT, OUT out_number FLOAT) BEGIN SET out_number=SQRT(input_number); END$$ DELIMITER ;
The procedure compiles fine. (I am using MySQL Query Browser in ubuntu).
However when I call the procedure:
CALL my_sqrt(4,@out_value);
(also in query browser)
It returns an error:
(1064) check the manual that correspond to the...
Why isn't this example working?
A Stored Procedure can have any number of output parameters. The simple logic is this — If you want to return 1 value then use 1 output parameter, for returning 5 values use 5 output parameters, for 10 use 10, and so on.
An input/output parameter is a parameter that functions as an IN or an OUT parameter or both. The value of the IN/OUT parameter is passed into the stored procedure/function and a new value can be assigned to the parameter and passed out of the module. An IN/OUT parameter must be a variable, not a constant.
The MySQL Stored procedure parameter has three modes: IN, OUT, and INOUT. When we declare an IN type parameter, the application must pass an argument to the stored procedure. It is a default mode. The OUT type parameter, the stored procedure returns a final output generated by SQL Statements.
By using IN OUT parameter we can pass values into a parameter and return a value to the calling program using the same parameter. But this is possible only if the value passed to the procedure and output value have a same datatype. This parameter is used if the value of the parameter will be changed in the procedure.
Unable to replicate. It worked fine for me:
mysql> CALL my_sqrt(4, @out_value); Query OK, 0 rows affected (0.00 sec) mysql> SELECT @out_value; +------------+ | @out_value | +------------+ | 2 | +------------+ 1 row in set (0.00 sec)
Perhaps you should paste the entire error message instead of summarizing it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With