GREATEST function
The GREATEST function returns the maximum value in a list of expressions.
The arguments to this function must be comma-separated expressions that evaluate to compatible data types.
This is the syntax of the GREATEST function:
Element | Description | Restrictions | Syntax |
---|---|---|---|
expression | Expression whose value can be compared | Data type cannot be a collection or a large object. | Expression |
The arguments must be of compatible data types. Arguments of complex data types, or BYTE, TEXT, BLOB, CLOB objects, or DISTINCT types based on any of these data types are not supported. Any user-defined data type that you specify as an argument to the GREATEST function must implement the greaterthan( ) function.
The database server converts the specified expression arguments, if necessary, to the data type of the returned value. This return data type is determined by all the operands of the expression, and the compatibility rule is consistent with CASE expressions.
The return value of the GREATEST function is its largest argument value. If one or more arguments evaluates to NULL, the result is NULL. If GREATEST is used to compare DATE or DATETIME values, the return value is the latest date.
Assume that table T1 contains three columns C1, C2,
and C3 with values 1
, 7
,
and 4
. The following query returns a value of 7
:
SELECT GREATEST (C1, C2, C3) FROM T1;
If
column C3 has a value of NULL instead of 4
,
however, the same query returns a NULL value.