SIGN
Declaration
SIGN(X)
Description
SIGN(X) returns the sign of the parameter, which depends on whether X is negative, zero, or positive. It supports floating-point numbers and hexadecimal numbers. The returned result is:
-
Negative value:
-1 -
Zero value:
0 -
Positive value:
1
This function supports comparison operations. The result is converted to a numeric type and returns 1 (TRUE) or 0 (FALSE).
If the input is NULL, the return value is NULL.
Examples
SELECT SIGN(-32), SIGN(0), SIGN(234);
+-----------+---------+-----------+
| SIGN(-32) | SIGN(0) | SIGN(234) |
+-----------+---------+-----------+
| -1 | 0 | 1 |
+-----------+---------+-----------+
1 row in set (0.001 sec)
SELECT SIGN(NULL),SIGN(FALSE),SIGN(0X01);
+------------+-------------+------------+
| SIGN(NULL) | SIGN(FALSE) | SIGN(0X01) |
+------------+-------------+------------+
| NULL | 0 | 1 |
+------------+-------------+------------+
1 row in set (0.001 sec)