Mysql Sign Function

MySQL: SIGN Function

This tutorial explains how to use the MySQL SIGN function with syntax and examples.

Description

The MySQL SIGN function returns a value indicating the sign of a number.

Syntax

The syntax for the SIGN function in MySQL is:

SIGN( number )

Parameters or Arguments

number

The number to test for its sign.

Note

  • The SIGN function returns -1, if the number is less than 0.
  • The SIGN function returns 0, if the number is equal to 0.
  • The SIGN function returns 1, if the number is greater than 0.

Applies To

The SIGN function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let's look at some MySQL SIGN function examples and explore how to use the SIGN function in MySQL.

For example:

mysql> SELECT SIGN(12);
Output: 1

mysql> SELECT SIGN(0);
Output: 0

mysql> SELECT SIGN(-12);
Output: -1