Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 The Oracle GREATEST Function      [Return To Index] Jump to:  
  Looking for the original pages? (formerly called "Morgan's Library") You can find them here.

Term: GREATEST

Definition:
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.)

Example Syntax:

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.

Example Usage:

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'


Notes:
  1. If the value returned by this function is character data, its datatype is always VARCHAR2.
  2. 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.
  3. If GREATEST is used to compare dates it will return the latest (most recent) date.


Related Links:

Related Code Snippets:
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 239 users online    © 2009 psoug.org
PSOUG LOGIN
Username: 
Password: 
Forgot your password?