0

Having a weird problem selecting session variables which are changed by a stored procedure.

 call calculate("input1", "input2",@price);
 select @price; /*price is 2.00*/


 call calculate("anotherinput","anotherinput2",@price);
 select @price; /*price is 3.00*/

However, the answer I get is actually 2 3.00's rather than the 2.00 then the 3.00. Assuming it's getting overwritten and messing it all up. But what's the best way to go about this?

1 Answers1

0

Procedure might have not defined the parameter price as an OUT parameter, but IN parameter. Unless which the passed IN parameter will always show the same OLD passed value.

Working Example:

mysql> create procedure test_sp( inout p int, in q int ) set p := p*q;
mysql> set @p := 4; set @q := 6;
mysql> delimiter //
mysql> call test_sp( @p, @q );
    -> select @p, @q;
    -> call test_sp( @p, @q );
    -> select @p, @q;
    -> //

+------+------+
| @p   | @q   |
+------+------+
|   24 |    6 |
+------+------+
1 row in set (0.00 sec)

+------+------+
| @p   | @q   |
+------+------+
|  144 |    6 |
+------+------+
1 row in set (0.01 sec)
Ravinder Reddy
  • 23,692
  • 6
  • 52
  • 82