MySQL SIGN() Function

In MySQL, the SIGN() function returns sign of the argument as 1, 0, or -1, depending on whether the argument is positive, zero, or negative.

SIGN() Syntax

Here is the syntax of MySQL SIGN() function:

SIGN(number)

Parameters

number
Required. A number.

Return value

The SIGN() function function returns sign of the argument as 1, 0, or -1, depending on whether the argument is positive, zero, or negative.

  • If number is positive, the function will return 1.
  • If number is zero, the function will return 0.
  • If number negative, the function will return -1.
  • If number is NULL, the function will return NULL.

SIGN() Examples

SELECT
    SIGN(123),
    SIGN(123.123),
    SIGN(-123),
    SIGN(-123.123),
    SIGN(0),
    SIGN(NULL)\G

output

*************************** 1\. row ***************************
     SIGN(123): 1
 SIGN(123.123): 1
    SIGN(-123): -1
SIGN(-123.123): -1
       SIGN(0): 0
    SIGN(NULL): NULL