Home » SQL » Find Max Value in List in Oracle

Find Max Value in List in Oracle

You can use the greatest() function in Oracle to find the maximum value in the list. Below are its syntax and examples:

Syntax

greatest(value1, value2, value3, ...)

Example-1:

The following SQL query will get the maximum value from the comma-separated list:

select greatest(5, 29, 99, 89) grt from dual;

Output:

99

Example-2:

Get the maximum value in string type data:

select greatest('a', 'k', 'j', 'b') grt from dual;

Output:

k

Example-3:

Getting the column that has the maximum value in Oracle:

select ename, sal, comm, 
       greatest(nvl(sal,0), nvl(comm,0)) highest_amt 
       from emp;

Output

ENAMESALCOMMHIGHEST_AMT
KING5000-5000
BLAKE2850-2850
CLARK245049894989
JONES2975-2975

See also: