In MySQL 5, at the moment you can't write a recursive stored
functions. It is forbidden.
Instead you can write a recursive stored procedure. That is not
permitted by default but modifying a variable you can achieve
such a recursion.
The variable is max_sp_recursion_depth
.
SET GLOBAL max_sp_recursion_depth = 0
.
A value of zero means: "no recursion" (the default value)
SET GLOBAL max_sp_recursion_depth=255
A value greater then zero means: the maximun number of nested
recursion in a procedure. Max value is 255.
Pay attention to the variable named thread_stack
, it
is the amount of memory allocated for the stack of a thread.
Writing a recursive routine the tipical error is to create an
infinite recursion An infinite recursion leads very soon to fill
up the stack. (the default value of the thread stack is less than
200K)
So, if you have …