Recursion Demo : Recursion « Procedure Function « SQL / MySQL






Recursion Demo

      

mysql>
mysql>
mysql>
mysql> delimiter $$
mysql>
mysql> CREATE FUNCTION factorial(n BIGINT) RETURNS BIGINT
    -> BEGIN
    ->    IF n>=2 THEN
    ->       RETURN n * factorial(n-1);
    ->    ELSE
    ->       RETURN n;
    ->    END IF;
    -> END$$
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> delimiter ;
mysql>
mysql>
mysql> SELECT factorial(6);
ERROR 1424 (HY000): Recursive stored functions and triggers are not allowed.
mysql>
mysql> drop function factorial;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>

   
    
    
    
    
    
  








Related examples in the same category