DELIMITER $$
CREATE PROCEDURE Mais_Um_Campo ( vMes INT)
BEGIN
DECLARE vQuantity INT;
DECLARE vPrice FLOAT;
DECLARE vRevenues FLOAT DEFAULT 0;
DECLARE cursor_end INT DEFAULT 0;
DECLARE c CURSOR FOR
SELECT INF.QUANTIDADE, FORMAT(INF.PRECO, 2) FROM ITENS_NOTAS INF
INNER JOIN NOTAS NF ON NF.NUMERO = INF.NUMERO
WHERE MONTH(NF.DATA_VENDA) = vMes AND YEAR(NF.DATA_VENDA) = 2017;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET cursor_end = 1;
OPEN c;
WHILE cursor_end = 0
DO
FETCH c INTO vQuantity, vPrice;
IF cursor_end = 0 THEN
SET vRevenues = vRevenues + (vQuantity * vPrice);
END IF;
END WHILE;
CLOSE c;
SELECT vRevenues;
END $$
DELIMITER ;
CALL Mais_Um_Campo (3);