Oracle / PLSQL: GREATEST Function

This article is written about how to use the Oracle/PLSQL GREATEST function with syntax and examples.


The Oracle/PLSQL GREATEST function returns the greatest value in a list of expressions.


The syntax for the GREATEST function in Oracle/PLSQL is:

GREATEST( expr1 [, expr2, ... expr_n] )

Parameters or Arguments


The first expression to be evaluated whether it is the greatest.

expr2, … expr_n

Optional. Additional expressions that are to be evaluated.


The GREATEST function returns a value that is the same datatype as expr1.


If the datatypes of the expressions are different, all expressions will be converted to whatever datatype expr1 is before comparing.

If the comparison is based on a character comparison, one character is considered greater than another if it has a higher character set value.

Applies To

The GREATEST function can be used in the following versions of Oracle/PLSQL:

Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i


Let’s look at some Oracle GREATEST function examples and explore how to use the GREATEST function in Oracle/PLSQL.

For example:

GREATEST(2, 5, 12, 3)
Result: 12

GREATEST('2', '5', '12', '3')
Result: '5'

GREATEST('apples', 'oranges', 'bananas')
Result: 'oranges'

GREATEST('apples', 'applis', 'applas')
Result: 'applis'