Open In App

SIGN() Function in MySQL

Last Updated : 28 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

SIGN() function in MySQL is used to return the sign of the given number. It returns 1 if the number is positive, -1 if the number is negative and 0 for zero.

Syntax :

 
SIGN(X)

Parameter :
SIGN() function accepts one parameter as input and will give you the results in values like Positive(+1),Negative(-1) and Zero(0).

  • X –A number whose sign we want to check.

Returns –
It returns the value of sign of the given number i.e. Positive(+1), Negative(-1) and Zero(0).

Example-1 :
Applying SIGN() function to Zero.

SELECT SIGN(0) AS Sign_Val;

Output :

Sign_Val 
0

Example-2 :
Applying SIGN() function to a positive number.

SELECT SIGN(12) AS Sign_Val;

Output :

Sign_Val 
1

Example-3 :
Applying SIGN() function to a negative number.

SELECT SIGN(-2) AS Sign_Val;
Sign_Val
-1

Example-4 :
Applying SIGN() function to a numeric column in a table.

Table -Number

X
+12
1.8
0
-1.8
-14
SELECT X, SIGN(X) AS X_Sign  FROM Number;

Output :

X X_Sign
12 1
1.8 1
0 0
-1.8 -1
-14 -1

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads