SIGN

The SIGN function returns an indicator of the sign of expression.

SIGN(expression)

The returned value is:

–1
if the argument is less than zero
-0
if the argument is DECFLOAT negative zero
0
if the argument is zero
1
if the argument is greater than zero
expression
An expression that returns a value of any built-in numeric, character-string, or graphic-string data type. A string argument is converted to double-precision floating point before evaluating the function. For more information about converting strings to double-precision floating point, see DOUBLE_PRECISION or DOUBLE.

The result has the same data type and length attribute as the argument, except that precision is increased by one if the argument is DECIMAL or NUMERIC and the scale of the argument is equal to its precision. For example, an argument with a data type of DECIMAL(5,5) will result in DECIMAL(6,5). If the precision is already the maximum precision (mp), the scale will be decreased by one. For example, DECIMAL(63,63) will result in DECIMAL(63,62).

If the argument can be null, the result can be null; if the argument is null, the result is the null value.

Example

  • Assume that host variable PROFIT is a large integer with a value of 50000.
      SELECT SIGN(:PROFIT)
        FROM EMPLOYEE
    Returns the value 1.