以经典的阶乘算法为例。
Oracle:
createorreplaceprocedure factorial(n in number, b out number)
is
c_in number;
c_out number;
begin
if n!=1 then
c_in := n-1;
factorial(c_in,c_out);
b := n*c_out;
else
b := 1;
end if;
end;
/
--调用
variable r number;
exec factorial(6,:r);
print r;
MySQL:
dropprocedure if exists factorial;
set @@session.max_sp_recursion_depth=99;
delimiter $$
createprocedure factorial (in n bigint, out b bigint)
begin
declare c_in bigint;
declare c_out bigint;
if n!=1 then
set c_in := n-1;
call factorial(c_in,c_out);
set b:=n*c_out;
else
set b:=1;
end if;
end$$
delimiter ;
--调用
call factorial(6,@r);
select @r;
--转自