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 :
Example-2 :
Applying SIGN() function to a positive number.
SELECT SIGN(12) AS Sign_Val;
Output :
Example-3 :
Applying SIGN() function to a negative number.
SELECT SIGN(-2) AS Sign_Val;
Example-4 :
Applying SIGN() function to a numeric column in a table.
Table -Number
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 |
Last Updated :
28 Sep, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...