DB2 Version 9.7 for Linux, UNIX, and Windows

TOTALORDER scalar function

Read syntax diagramSkip visual syntax diagram
>>-TOTALORDER--(--decfloat-expression1--,--decfloat-expression2--)-><

The schema is SYSIBM.

The TOTALORDER function returns a SMALLINT value of -1, 0, or 1 that indicates the comparison order of two arguments.

decfloat-expression1
An expression that returns a value of any built-in numeric data type. If the argument is not DECFLOAT(34), it is logically converted to DECFLOAT(34) for processing.
decfloat-expression2
An expression that returns a value of any built-in numeric data type. If the argument is not a decimal floating-point value, it is converted to DECFLOAT(34) for processing.

Numeric comparison is exact, and the result is determined for finite operands as if range and precision were unlimited. An overflow or underflow condition cannot occur.

If one value is DECFLOAT(16) and the other is DECFLOAT(34), the DECFLOAT(16) value is converted to DECFLOAT(34) before the comparison is made.

The semantics of the TOTALORDER function are based on the total order predicate rules of IEEE 754R. TOTALORDER returns the following values:
  • -1 if decfloat-expression1 is lower in order compared to decfloat-expression2
  • 0 if both decfloat-expression1 and decfloat-expression2 have the same order
  • 1 if decfloat-expression1 is higher in order compared to decfloat-expression2
The ordering of the special values and finite numbers is as follows:
-NAN<-SNAN<-INFINITY<-0.10<-0.100<-0<0<0.100<0.10<INFINITY<SNAN<NAN

The result of the function is a SMALLINT value. If either argument can be null, the result can be null; if either argument is null, the result is the null value.

Examples: