All Products
Search
Document Center

LEAST

Last Updated: Jun 18, 2021

The LEAST function returns the minimum value in a list of one or more expressions. The database uses the first parameter expr to determine the return type. If the data type of the remaining parameters is different from that of the first parameter expr, ApsaraDB for OceanBase implicitly converts each parameter that follows the first parameter expr to the data type of the first parameter expr before the comparison.

Syntax

LEAST(expr [, expr ]...)

Parameters

Parameter

Description

expr

An expression or an expression list. The data type can be NUMBER, FLOAT, BINARY_FLOAT, BINARY_DOUBLE, CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB.

Return type

If the data type of the first parameter expr is NUMBER, FLOAT, BINARY_FLOAT, or BINARY_DOUBLE, the function returns the data type that is the same as the data type of the first parameter expr. If the data type of the first parameter expr is CHAR, VARCHAR2, or CLOB, the function returns the VARCHAR2 type. If the data type of the first parameter expr is NCHAR or NVARCHAR2, the function returns the NVARCHAR2 type.

Examples

The following statement compares the sizes of strings and returns the minimum string:

SELECT LEAST('HAPPY', 'HAPPEN', 'HAPPINESS') "Least"
  FROM DUAL;

The following result is returned:

+--------+
| Least  |
+--------+
| HAPPEN | 
+--------+

The following statement compares the sizes of the 1 integer, the 3.925 string, and the 2.4 string. The sizes can be compared after the remaining parameters are implicitly converted to the numeric data type. This is because the data type of the first parameter is the numeric data type.

SELECT LEAST (1, '3.925', '2.4') "Least"
  FROM DUAL;

The following result is returned:

+-------+
| Least |
+-------+
|     1 | 
+-------+