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

sign

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

Syntax

sign(DOUBLE a) 

Parameters

Parameter

Mandatory

Type

Description

a

Yes

DOUBLE, BIGINT, DECIMAL, or STRING

The format of parameter a includes floating-point format, integer format, and string format.

Return Values

Returns a value of type DOUBLE.

  • If a is positive, 1 is returned.
  • If a is negative, -1 is returned.
  • If a is 0, 0 is returned.
  • If a is NULL, NULL is returned.

Example Code

Returns -1.

select sign(-3); 

Returns 1.

select sign(3); 

Returns 0.

select sign(0); 

Returns 1.

select sign(3.1415926); 

Returns NULL.

select sign(null);