MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB SIGN() Function



The MariaDB SIGN() function returns a value indicating the sign of the specified number. It returns the following:

  • Returns -1, if the number is less than 0.
  • Returns 0, if the number is equal to 0.
  • Returns 1, if the number is greater than 0.

Syntax

SIGN(number)

Parameters

number Required. Specify the number to test for its sign.

Return Value

Returns a value indicating the sign of the given number.

Example 1:

The example below shows the usage of SIGN() function.

SELECT SIGN(25);
Result: 1

SELECT SIGN(-25);
Result: -1

SELECT SIGN(0);
Result: 0

Example 2:

Consider a database table called Sample with the following records:

Datax
Data 110
Data 214
Data 3-34
Data 40
Data 5-67

The statement given below can be used to get the sign of values of column x.

SELECT *, SIGN(x) AS SIGN_Value FROM Sample;

This will produce the result as shown below:

DataxSIGN_Value
Data 1101
Data 2141
Data 3-34-1
Data 400
Data 5-67-1

❮ MariaDB Functions