SQL Tutorial SQL Advanced SQL Database SQL References

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:

Datax
Data 110
Data 214
Data 3-34
Data 40
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:

DataxSIGN_Value
Data 1101
Data 2141
Data 3-34-1
Data 400
Data 5-67-1

❮ Oracle Functions