Syntax
SIGN(X)
Purpose
You can call SIGN(X) to return the sign of the argument. The value returned depends on whether X is a negative number, zero, or a positive number. Floating-point numbers and hexadecimal numbers are supported. Return values:
If X is a negative number,
-1is returned.If X is zero,
0is returned.If X is a positive number,
1is returned.
The function also supports comparison operation. The comparison result is converted to a numeric value. The result is 1 (TRUE) or 0 (FALSE).
If you enter NULL, the return value is NULL.
Examples
obclient> SELECT SIGN(-32), SIGN(0), SIGN(234);
+-----------+---------+-----------+
SIGN(-32) SIGN(0) SIGN(234)
+-----------+---------+-----------+
-1 0 1
+-----------+---------+-----------+
1 row in set (0.01 sec)
obclient> SELECT SIGN(NULL),SIGN(FALSE),SIGN(0X01);
+------------+-------------+------------+
SIGN(NULL) SIGN(FALSE) SIGN(0X01)
+------------+-------------+------------+
NULL 0 1
+------------+-------------+------------+
1 row in set (0.00 sec)