DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `getMin`(
a int,
b int
) RETURNS int(11)
BEGIN
declare min int;
if(a>b)
then set min = b;
elseif(b>a)
then set min = a;
else set min =0;
#end if;
end if;
RETURN min;
CREATE DEFINER=`root`@`localhost` FUNCTION `getMin`(
a int,
b int
) RETURNS int(11)
BEGIN
declare min int;
if(a>b)
then set min = b;
elseif(b>a)
then set min = a;
else set min =0;
#end if;
end if;
RETURN min;
END
调用该函数可以如下方式
select getMin(1,2);
返回值为1