Decode Function; Considerations For Decode - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

DECODE Function

The DECODE function compares expr to each test_expr value one by one in the order
provided. If expr is equal to a test_expr, then the corresponding retval is returned. If no
match is found, default is returned. If no match is found and default is omitted, NULL is
returned.
DECODE is a Neoview extension.
DECODE (expr, test_expr, retval [, test_expr2, retval2 ... ] [ , default ] )
expr
is an SQL expression.
test_expr, test_expr,..
are each an SQL expression of a type comparable to that of expr.
retval
is an SQL expression.
default, retval2,..
are each an SQL expression of a type comparable to that of retval.

Considerations for DECODE

In a DECODE function, two nulls are considered to be equivalent. If expr is null, then the
returned value is the retval of the first test_expr that is also null.
The expr, test_expr, retval, and default values can be derived from expressions.
The arguments can be any of the numeric types or character types. However, expr and each
test_expr value must be of comparable types. If expr and test_expr values are character
types, they must be in the same character set (to be comparable types.)
All the retval values and the default value, if any, must be of comparable types.
If expr and a test_expr value are character data, the comparison is made using nonpadded
comparison semantics.
If expr and a test_expr value are numeric data, the comparison is made with a temporary
copy of one of the numbers, according to defined rules of conversion. For example, if one number
is INTEGER and the other is DECIMAL, the comparison is made with a temporary copy of the
integer converted to a decimal.
If all the possible return values are of fixed-length character types, the returned value is a
fixed-length character string with size equal to the maximum size of all the possible return value
types.
If any of the possible return values is a variable-length character type, the returned value is a
variable-length character string with maximum size of all the possible return value types.
If all the possible return values are of integer types, the returned value is the same type as the
largest integer type of all the possible return values.
If the returned value is of type FLOAT, the precision is the maximum precision of all the possible
return values.
If all the possible returned values are of the same non-integer, numeric type (REAL, FLOAT,
DOUBLE PRECISION, NUMERIC, or DECIMAL), the returned value is of that same type.
If all the possible return values are of numeric types but not all the same, and at least one is
REAL, FLOAT, or DOUBLE PRECISION, then the returned value is of type DOUBLE PRECISION.
If all the possible return values are of numeric types but not all the same, none are REAL, FLOAT,
or DOUBLE PRECISION, and at least one is of type NUMERIC, then the returned value is of
type NUMERIC.
330
SQL Functions and Expressions

Advertisement

Table of Contents
loading

Table of Contents