SQLite sign() Function
The SQLite sign() function returns the sign of the specified number, and returns 1, -1, or 0 respectively if the parameter is positive, negative, or zero.
Syntax
Here is the syntax of the SQLite sign() function:
sign(num)
Parameters
num-
Required. a number.
Return value
The return value of the SQLite sign() function is 1, -1, 0, which represent positive, negative, and zero parameters, respectively:
- If
numis greater than0, thesign()function will return1. - If
numequals0, thesign()function will return0. - If
numis less than0, thesign()function will return-1.
If the parameter is a NULL or a string or other value that cannot be converted to a number, this function will return NULL.
Examples
This example shows how to use sign() the basic usage of the SQLite function:
SELECT
sign(123),
sign(123.123),
sign(-123),
sign(-123.123),
sign(0);
sign(123) = 1
sign(123.123) = 1
sign(-123) = -1
sign(-123.123) = -1
sign(0) = 0