Syntax
SIGN(X)
Purpose
SIGN(X) returns 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 are as follows:
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 operations. The comparison result is converted to a numeric value. The result is 1 (TRUE) or 0 (FALSE).
If you enter NULL, NULL is returned.
Examples
obclient> SELECT SIGN(-32), SIGN(0), SIGN(234);
+-----------+---------+-----------+
| SIGN(-32) | SIGN(0) | SIGN(234) |
+-----------+---------+-----------+
| -1 | 0 | 1 |
+-----------+---------+-----------+
1 row in set
obclient> SELECT SIGN(NULL),SIGN(FALSE),SIGN(0X01);
+------------+-------------+------------+
| SIGN(NULL) | SIGN(FALSE) | SIGN(0X01) |
+------------+-------------+------------+
| NULL | 0 | 1 |
+------------+-------------+------------+
1 row in set