/*
Autor : Joel Fernandez
Fecha : 08/10/2015
IDE : MySQL Workbench
Web : www. codebotic.com
Tema : FUnciones en MySQL
*/
-- 2° crear una calculadora aritmetica
delimiter $$
create function calculadora(op char(1), x int, y int )
returns float
begin
declare operacion float;
case op
when \'+\' then set operacion=x+y;
when \'-\' then set operacion=x-y;
when \'*\' then set operacion=x*y;
when \'/\' then set operacion=x/y;
end case;
return operacion*1.0;
end
$$
select calculadora(\'/\',10,3); -- puede ser +, - , * , /