Search code examples
mysqlstored-procedures

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) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT @out_value' at line 2

Why isn't this example working?


Solution

  • 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.