GREATEST and LEAST

GREATEST and LEAST#

Functionality:#

These Oracle functions will evaluate each of the variables passed, and return the one that has the highest or lowest value.

Parameters:#

Expression1 The first value you wish to evaluate
Expression2 The second value you wish to evaluate
... et cetera as many values that you wish to evaluate

Returns:#

The same variable type as Expression1

Errors:#

None

Operations: #

The function will evaluate the value passed in Expression1, and compare all the other values passed using that variable type. This is an important consideration if you are comparing dates that are represented as text or text that contains numbers etc.

Example:#

GREATEST(45,290) will evaluate the values passed as numbers and will return 290

GREATEST('45','290') will evaluate the values passed as text (because the first parameter is text) and will return '45' (the highest value, alphanumerically – “4” comes after “2”)

LEAST('14-May-2006','30-Jun-2005’) will evaluate the values passed as text and will return ’14-May-2006’ (the lowest value, alphanumerically – “1” comes before “3”)

LEAST(to_date('14-May-2006'),to_date('30-Jun-2005')) will evaluate the values passed as dates and will return 30-Jun-2005 (the earliest date)


Notes #

Click to create a new notes page