I have the following procedure:
DELIMITER $$
CREATE PROCEDURE sp_CalculaVolume (
IN vReservatorioCodigo bigint,
OUT Retorno decimal
)
BEGIN
Declare Formato int;
Declare TipoReservatorio bigint;
Declare retorno decimal;
Declare vAltura decimal;
DECLARE vDiametro decimal;
Declare vRaio decimal;
Declare vAresta1 decimal;
Declare vAresta2 decimal;
SELECT @Formato := IFNULL(t.Formato, 0),
@vAltura := d.Altura,
@vAresta1 := d.Aresta1,
@vAresta2 := d.Aresta2,
@vDiametro := d.Diametro
From TipoReservatorio t
INNER JOIN Reservatorio r ON (t.Codigo = r.TipoReservatorioCodigo)
INNER JOIN DimensaoReservatorio d ON (t.DimensaoReservatorioCodigo = d.Codigo)
WHERE r.Codigo = vReservatorioCodigo;
IF Formato = 1 THEN
SET vRaio = vDiametro / 2;
SET retorno = 3.14 * (vRaio * vRaio) * vAltura;
ELSE
SET retorno = vAresta1 * vAresta2 * Altura;
END
END$$
Delimiter ;
As can be seen, the return parameter is set to OUT and I would like to have this parameter returned when calling this procedure. But this is not what happens. When I run:
CALL sp_RetornaValor(1, @val);
SELECT @val
As can be seen, the OUT parameter is not returning, but rather the result of the SELECT that I have inside the Procedure.