SIGN

SIGN is a mathematical function in SQL that returns the positive, negative or zero sign of a specific number. The returned values are +1, -1, or 0 indicating whether the number is positive, negative or zero respectively.

SIGN(X)

  • x: This parameter corresponds to the numeric value whose sign you want to calculate. If X is positive, the SIGN function will return 1. If X is negative, the SIGN function will return -1. If X is zero, the SIGN function will return 0.

Example

SELECT SIGN(-15);
SELECT SIGN(0);
SELECT SIGN(45);

Output

-1
0
1

Explanation

In the given example, the SIGN() function returns -1 when the argument is negative (-15), 0 when the argument is zero (0), and 1 when the argument is positive (45). This function is useful for categorizing data into positive, negative, and zero groups.

SIGN( numeric_expression )

  • numeric_expression: This is the value for which the SIGN function is to be calculated. It can be an integer, a decimal, a float, or any value that can be passed as a numeric expression.

Example

SELECT SIGN(-10) AS SignValue

Output

SignValue
-----------
-1

Explanation

The SIGN function in SQL Server is used to determine whether the number is positive, negative, or zero. It returns -1 when the number is negative, 0 when the number is zero, and 1 when the number is positive. In this example, the SIGN function returned -1 because -10 is a negative number.

SIGN(n NUMBER) RETURN NUMBER;

  • n number: Input parameter that takes a numeric value, used by the Oracle SIGN function to return the sign of this number. Supports both positive and negative numbers as well as zero.

Example

SELECT SIGN(-15) FROM dual;

Output

-1

Explanation

The SIGN function in Oracle takes a single argument and returns -1, 0, or 1 based on whether the argument is negative, zero, or positive. In the provided example, the function returns -1 because the argument (-15) is negative.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.