DECFLOAT_SORTKEY

The DECFLOAT_SORTKEY function returns a binary value that may be used to sort DECFLOAT values.

Read syntax diagramSkip visual syntax diagramDECFLOAT_SORTKEY( expression)

The DECFLOAT_SORTKEY function returns a binary value that may be used to sort decimal floating-point values in a manner that is consistent with the IEEE 754R specification on total ordering.

expression
An expression that returns a value of any built-in numeric, character-string, or graphic-string data type.

If the data type of the argument is SMALLINT, INTEGER, REAL, DOUBLE, DECIMAL(p,s) where p <=16, or NUMERIC(p,s) where p <=16, then the argument is converted to DECFLOAT(16) for processing. Otherwise, the argument is converted to DECFLOAT(34) for processing.

The result of the function is BINARY(9) if the argument is DECFLOAT(16) or BINARY(17) if the argument is DECFLOAT(34).

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

Example

CREATE TABLE T1 (D1 DECFLOAT(16));
INSERT INTO T1 VALUES(2.100);
INSERT INTO T1 VALUES(2.10);
INSERT INTO T1 VALUES(2.1000);
INSERT INTO T1 VALUES(2.1);

SELECT D1 FROM T1 ORDER BY D1;

     D1
----------------
          2.100
           2.10
         2.1000
            2.1

Note that this result set is arbitrary. The ORDER BY has no effect on ordering these values.
SELECT D1 FROM T1 ORDER BY DECFLOAT_SORTKEY(D1);

     D1
----------------
         2.1000
          2.100
           2.10
            2.1

Note that this result set is ordered according to the IEEE 745R ordering specification.