Oracle SIGN() Function
The Oracle (PL/SQL) SIGN() function returns a value indicating the sign of the specified number. It returns the following:
- Returns -1, if the number is less than 0.
- Returns 0, if the number is equal to 0.
- Returns 1, if the number is greater than 0.
For binary floating-point numbers (BINARY_FLOAT and BINARY_DOUBLE), this function returns the sign bit of the number. The sign bit is:
- Returns -1, if the number is less than 0.
- Returns +1, if the number is greater than or equal to 0 or NaN.
Syntax
SIGN(number)
Parameters
number |
Required. Specify the number to test for its sign. |
Return Value
Returns a value indicating the sign of the given number.
Example 1:
The example below shows the usage of SIGN() function.
SIGN(25) Result: 1 SIGN(-25) Result: -1 SIGN(0) Result: 0
Example 2:
Consider a database table called Sample with the following records:
Data | x |
---|---|
Data 1 | 10 |
Data 2 | 14 |
Data 3 | -34 |
Data 4 | 0 |
Data 5 | -67 |
The statement given below can be used to get the sign of values of column x.
SELECT Sample.*, SIGN(x) AS SIGN_Value FROM Sample;
This will produce the result as shown below:
Data | x | SIGN_Value |
---|---|---|
Data 1 | 10 | 1 |
Data 2 | 14 | 1 |
Data 3 | -34 | -1 |
Data 4 | 0 | 0 |
Data 5 | -67 | -1 |
❮ Oracle Functions