FACTORIAL
Description
Returns the factorial of x, or NULL if x is not in the range 0 to 20 (including 0 and 20).
Syntax
FACTORIAL(<x>)
Parameters
| Parameter | Description |
|---|---|
<x> | The value for which the factorial is to be calculated |
Return Value
The factorial value of parameter x.
Special Cases
- When
xequals 0, returns 1 - When
xis not in the range [0, 20], returnsNULL - When
xis NULL, returns NULL
Examples
select factorial(0);
+--------------+
| factorial(0) |
+--------------+
| 1 |
+--------------+
select factorial(-1);
+---------------+
| factorial(-1) |
+---------------+
| NULL |
+---------------+
select factorial(21);
+---------------+
| factorial(21) |
+---------------+
| NULL |
+---------------+
select factorial(20);
+---------------------+
| factorial(20) |
+---------------------+
| 2432902008176640000 |
+---------------------+
select factorial(NULL);
+-----------------+
| factorial(NULL) |
+-----------------+
| NULL |
+-----------------+