Friday, January 11, 2013

Greatest Function


In Oracle/PLSQL, the greatest function returns the greatest value in a list of expressions.

Syntax

The syntax for the greatest function is:
greatest( expr1, expr2, ... expr_n )
expr1expr2, . expr_n are expressions that are evaluated by the greatest function.

Note

If the datatypes of the expressions are different, all expressions will be converted to whatever datatype expr1 is.
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

  • Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

For Example

greatest(2, 5, 12, 3)would return 12
greatest('2', '5', '12', '3')would return '5'
greatest('apples', 'oranges', 'bananas')would return 'oranges'
greatest('apples', 'applis', 'applas')would return 'applis'