Hitachi

Hitachi Advanced Database SQL Reference


8.4.10 SIGN

Returns the sign of the target data (+1 for positive, -1 for negative, 0 for zero).

Organization of this subsection

(1) Specification format

scalar-function-SIGN ::= SIGN(target-data)
 
  target-data ::= value-expression

(2) Explanation of specification format

target-data:

Specifies the numeric data to be processed.

The following rules apply:

(3) Rules

  1. The data type of the execution result is determined based on the data type of the target data, as shown in the following table:

    Table 8‒7: Data type of the execution result of the scalar function SIGN

    No.

    Data type of target data

    Data type of the execution result

    1

    BIGINT

    BIGINT#

    2

    INTEGER

    INTEGER

    3

    SMALLINT

    SMALLINT

    4

    DECIMAL(p,s)

    DECIMAL(1,0)

    5

    NUMERIC(p,s)

    6

    DOUBLE PRECISION

    DOUBLE PRECISION

    7

    FLOAT

    8

    REAL

    REAL

    #

    If the integer data type format is a legacy format, it will be an INTEGER type.

  2. The NOT NULL constraint does not apply to the value of the execution result (the null value is allowed).

  3. If the target data is a null value, the execution result will be a null value.

(4) Example

Example:

Determine whether the values of columns C1 to C3 in table T1 are positive, negative, or zero.

SELECT SIGN("C1"),SIGN("C2"),SIGN("C3") FROM "T1"

[Figure]