The Oracle/PLSQL GREATEST function returns the greatest or largest value in a list of values or expressions. Oracle compares the expressions using nonpadded comparison semantics.
If the datatypes of the values or expressions are different, all of the values and expressions will be converted to the same datatype as value_1 is.
If the comparison is between characters (quoted strings), one character will be considered "greater" than another character if it has a higher character set value. This is usually based on the ASCII value, but may differ for other character sets or Unicode values.
The GREATEST function returns NULL whenever it receives a NULL parameter, regardless of the particular value that is NULL. (In general, functions that take a set of inputs will return NULL when a deciding input is NULL.)
GREATEST( value_1, value_2, ... value_n )
value_1, value_2, ... value_n are the values or expressions that are evaluated by the GREATEST function.
GREATEST(7, 19, 85, 2) returns '85'
GREATEST('2', '19', '6', '14') returns '6'
GREATEST('dallas', 'seattle', 'miami') returns 'seattle'
GREATEST('dallas', 'dulles', 'dullus') returns 'dullus'
GREATEST('blue', 'blew', 'blow') returns 'blue'
- If the value returned by this function is character data, its datatype is always VARCHAR2.
- Do not confuse GREATEST with MAX. GREATEST returns the greatest of the list of expressions, while MAX returns the maximum value of expressions and is normally used as an aggregate or analytic function.
- If GREATEST is used to compare dates it will return the latest (most recent) date.
Related Code Snippets: