GREATEST
GREATEST(expr [,expr...])

Returns the highest value from the list of arguments supplied. The GREATEST function can be used with character strings and dates, as well as with numbers.

Examples

Return the largest value from a list of numbers:

SQL> SELECT GREATEST(1,2,3) FROM dual;

GREATEST(1,2,3)
---------------
              3

Return the largest value from a list of character strings:

SQL> SELECT GREATEST('One','Two') FROM dual;

GRE
---
Two

Return the largest (most recent) value from a list of dates:

SQL> SELECT GREATEST(TO_DATE('11/15/1961','MM/DD/YYYY'),
  2                  TO_DATE('12/29/1988','MM/DD/YYYY'))
  3  FROM dual;

GREATEST(
---------
29-DEC-88

If you mix datatypes, Oracle uses the datatype of the first argument as a base and converts (if possible) all other arguments to that type before choosing the greatest value.

Get Oracle SQL: the Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.