Oracle / PLSQL: LEAST Function

This article is written about how to use the Oracle/PLSQL LEAST function with syntax and examples.

Description

The Oracle/PLSQL LEAST function returns the smallest value in a list of expressions.

Syntax

The syntax for the LEAST function in Oracle/PLSQL is:

LEAST( expr1 [, expr2, ... expr_n] )

Parameters or Arguments

expr1

The first expression to evaluate whether it is the smallest.

expr2, … expr_n

Optional. Additional expressions that are to be evaluated.

Returns

The LEAST function returns a value that is the same datatype as expr1.

Having a NULL value in one of the expressions will return NULL as the least value.

Note

If the datatypes of the expressions are different, all expressions will be converted to whatever datatype expr1 is.

If the comparison is based on a character comparison, one character is considered smaller than another if it has a lower character set value.

Applies To

The LEAST function can be used in the following versions of Oracle/PLSQL:

Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i

Example

Let’s look at some Oracle LEAST function examples and explore how to use the LEAST function in Oracle/PLSQL.

For example:

LEAST(2, 5, 12, 3)
Result: 2

LEAST('2', '5', '12', '3')
Result: '12'

LEAST('apples', 'oranges', 'bananas')
Result: 'apples'

LEAST('apples', 'applis', 'applas')
Result: 'applas'

LEAST('apples', 'applis', 'applas', null)
Result: NULL