Updated on 2023-10-25 GMT+08:00

factorial

This function is used to return the factorial of a.

Syntax

factorial(INT a)

Parameters

Table 1 Parameter

Parameter

Mandatory

Type

Description

a

Yes

BIGINT, INT, SMALLINT, or TINYINT

The value is an integer.

If the value is not of the INT type, the system will implicitly convert it to the INT type for calculation.

The string is converted to its corresponding ASCII code.

Return Values

The return value is of the BIGINT type.

  • If the value of a is 0, 1 is returned.
  • If the value of a is NULL or outside the range of [0,20], NULL is returned.

Example Code

The value 720 is returned.

select factorial(6);

The value 1 is returned.

select factorial(1);

The value 120 is returned.

select factorial(5.123456);

The value NULL is returned.

select factorial(null);

The value NULL is returned.

select factorial(21);