Oracle/PLSQL: Greatest Function
Here is what the documentation says :
GREATEST- GREATEST returns the greatest of the list of expressions. All expressions after the first are implicitly converted to the datatype of the first expression before the comparison. Oracle compares the exprsessions using nonpadded comparison semantics. Character comparison is based on the value of the character in the database character set. One character is greater than another if it has a highercharacter set value. If the value returned by this function is character data, its datatype is always VARCHAR2.
Syntax:
The syntax for the greatest function is:
greatest( expr1, expr2, ... expr_n )
expr1, expr2, . expr_n are expressions that are evaluated by the greatest function.
Example:
SELECT GREATEST ('A', 'B', 'C') "Greatest" FROM DUAL;
Greatest
--------
C
SELECT GREATEST (1, 9, 11) "Greatest" FROM DUAL;
Greatest
--------
11
SELECT GREATEST ('1', '9', '11') "Greatest" FROM DUAL;
Greatest
--------
9
GREATEST is not to be used on a singular item. Although it will return values with single item, as input the effect is not useful. Use GREATEST when you need to get the greatest values from a list of values. MAX on the other hand will return the max value on a column.
Applies To: * Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
No comments:
Post a Comment