DELIMITER $$
USE `sucos_vendas`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `mais_um_campo`(vMes int, vAno int)
BEGIN
declare fim_do_cursor int default 0;
declare vQuantidade int;
declare vPreco float;
declare vFaturamento float default 0;
declare c cursor for
select INF.QUANTIDADE, INF.PRECO
from
itens_notas_fiscais INF
inner join
notas_fiscais NF
on NF.NUMERO = INF.NUMERO
where month(NF.DATA_VENDA) = vMes and year(NF.DATA_VENDA) = vAno;
declare continue handler for not found set fim_do_cursor = 1;
open c;
while fim_do_cursor = 0
do
fetch c into vQuantidade, vPreco;
if fim_do_cursor = 0 then
set vFaturamento = vFaturamento + (vQuantidade * vPreco);
end if;
end while;
close c;
select vFaturamento as TOTAL_LIMITE_MES;
END$$
DELIMITER ;
;