Updated on 2026-11-06 GMT+08:00

factorial

The factorial function is used to return the factorial of a.

Syntax

factorial(INT a) 

Parameters

Parameter

Mandatory

Type

Description

a

Yes

BIGINT, INT, SMALLINT, or TINYINT

The format of parameter a is an integer format. If parameter a is not of type INT, it is implicitly converted to INT type before evaluation. Strings are converted to their corresponding ASCII codes.

Return Values

Returns a value of type BIGINT.

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

Example Code

Returns 720.

select factorial(6); 

Returns 1.

select factorial(1); 

Returns 120.

select factorial(5.123456); 

Returns NULL.

select factorial(null); 

Returns NULL.

select factorial(21);