Oracle SIGN() Function
Oracle SIGN() is a built-in function that returns -1, 0, or 1 to indicate the given number is negative, zero or positive.
Oracle SIGN() syntax
Here is the syntax for the Oracle SIGN() function:
SIGN(num)
Parameters
num-
Required.
Return Value
The Oracle SIGN() function returns -1, 0, or 1 to indicate whether the given number is negative, zero, or positive. The implementation rules of this function are as follows:
-
For values โโof
NUMBERtype:- If
nis less than 0, the sign is-1 - If
nequals to 0, the sign is0 - If
nis greater than 0, the sign is1
- If
-
For binary floating-point numbers (
BINARY_FLOATandBINARY_DOUBLE), this function returns the sign bit of the number:- If
nis less than 0, the sign is-1. - If
nis greater than or equal to 0, ornequals toNaN, the sign is1.
- If
If any parameter is NULL, SIGN() will return NULL.
Oracle SIGN() Examples
Here are some examples that demonstrate the usage of the Oracle SIGN() function.
Basic Usage
SELECT
SIGN(5),
SIGN(0),
SIGN(-5)
FROM dual;
Output:
SIGN(5) SIGN(0) SIGN(-5)
__________ __________ ___________
1 0 -1NaN
For NaN values, the Oracle SIGN() function returns 1.
SELECT
SIGN(BINARY_DOUBLE_NAN),
SIGN(BINARY_FLOAT_NAN)
FROM dual;
Output:
SIGN(BINARY_DOUBLE_NAN) SIGN(BINARY_FLOAT_NAN)
__________________________ _________________________
1 1NULL Parameters
If any parameter is NULL, SIGN() will return NULL.
SET NULL 'NULL';
SELECT
SIGN(NULL)
FROM dual;
Output:
SIGN(NULL)
_____________
NULLIn this example, we use the statement SET NULL 'NULL'; to display NULL values as the string 'NULL'.
Conclusion
Oracle SIGN() is a built-in function that returns -1, 0, or 1 to indicate the given number is negative, zero or positive.