MySQL SIGN Function

MySQL SIGN function is one of the Numeric Functions, which is to return the sign of the specified expression. And the return value is either Positive (+1), Negative (-1), or Zero (0). The basic syntax of it is as shown below:

SELECT SIGN(Numeric_Expression)
FROM Source
  • If the Expression is Zero, it returns Zero as a result.
  • If the Numeric_Expression is a Negative Number, it returns a Negative One(-1) as a result.
  • And If the Expression is a positive number, it returns a Positive One(+1).

To demonstrate this SIGN Numeric function, we are going to use the below shown data.

MySQL SIGN Function Example

This method finds and returns the sign of a specified value. The following query shows multiple ways to use this.

-- Finding for Negative Value
SELECT SIGN(-240.75) AS `SignValue`;

-- Finding for Positive Value
SELECT SIGN(125.267) AS `SignValue`;

-- Finding for Zero
SELECT SIGN(0) AS `SignValue`;

-- of string value
SELECT SIGN('125.274') AS `SignValue`;

-- Example on String
SELECT SIGN('MySQL') AS `SignValue`;

-- Example on NULLs
SELECT SIGN('NULL') AS `SignValue`;

From the screenshot below, you can see that we used it on different values.

SIGN Function Example 1

and

Example 2

The MySQL example of the Numeric method also allows you to check the value for the column data. In this example, we are going to find the sign value for all the records present in the Service Grade column.

SELECT Product, Color,
		StandardCost, Sales, TaxAmt,
        ServiceGrade,
        SIGN(ServiceGrade) AS `Grade Sign`
FROM `numeric functions`;
SIGN Function Example 3