Purpose
This function returns the maximum value from a list of one or more expressions.
Syntax
GREATEST(expr [, expr ]...)
Parameters
The expr parameter is an expression or a list of expressions. The data type can be NUMBER, FLOAT, BINARY_FLOAT, BINARY_DOUBLE, CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB.
Return type
The database uses the first expr parameter to determine the return type. If the data types of the remaining parameters differ from the data type of the first expr parameter, the database implicitly converts each subsequent parameter to the data type of the first expr parameter.
If the data type of the first
exprparameter isNUMBER,FLOAT,BINARY_FLOAT, orBINARY_DOUBLE, the return type is the same as the data type of the firstexprparameter.If the data type of the first
exprparameter isCHAR,VARCHAR2, orCLOB, the return type isVARCHAR2.If the data type of the first
exprparameter isNCHARorNVARCHAR2, the return type isNVARCHAR2.
Examples
Compare the strings
AC,BB, andCand return the largest string.obclient> SELECT GREATEST('AC','BB','C') "MAX" FROM DUAL; +-----+ | MAX | +-----+ | C | +-----+ 1 row in setCompare the integers
1, the string6, and the value5.555and return the largest value.obclient> SELECT GREATEST (1,'6','5.555') "MAX" FROM DUAL; +-----+ | MAX | +-----+ | 6 | +-----+ 1 row in set
