Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql stored-procedure: out parameter

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?

like image 223
domagojk Avatar asked Jul 11 '09 12:07

domagojk


People also ask

Can stored procedure have output parameter?

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.

What is in out parameter in stored procedure?

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.

What is out parameter in MySQL?

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.

How do you pass out a parameter in a procedure?

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.


1 Answers

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.

like image 177
chaos Avatar answered Oct 14 '22 16:10

chaos