Knowing the Sign of a Given Number in MySQL

Knowing the Sign of a Given Number in MySQL

For a given number, it may be necessary to know the sign of the number for computation purposes.

If it is positive, zero or negative, you may have respective case to work on. The signs are returned as 1, 0, -1 for positive number, zero and negative number respectively.

Case 1: Positive number

SELECT SIGN(234) AS SIGN;where 234 is the value. +-------+| SIGN  |+-------+|    1  |+-------+

Case 2: Number is zero

SELECT SIGN(0) AS SIGN;where 0 is the value. +-------+| SIGN  |+-------+|    0  |+-------+

Case 3: Negative number

SELECT SIGN(-64500) AS SIGN;where -64500 is the value. +-------+| SIGN  |+-------+|   -1  |+-------+ 

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist