GREATEST

2024-04-19 08:42:51  Updated

Purpose

GREATEST() returns the greatest value in a list of one or more expressions.

Syntax

GREATEST(expr [, expr ]...)

Parameters

expr is a list of one or more expressions. It can be of the NUMBER, FLOAT, BINARY_FLOAT, BINARY_DOUBLE, CHAR, VARCHAR2, NCHAR, NVARCHAR2, or CLOB data type.

Return type

OceanBase Database uses the first expr to determine the return type. If the remaining arguments have different data types from that of the first expr, OceanBase Database implicitly converts each argument after the first expr to the data type of the first expr.

  • If the first expr is of the NUMBER, FLOAT, BINARY_FLOAT, or BINARY_DOUBLE data type, the return type is the same as the data type of the first expr.

  • If the first expr is of the CHAR, VARCHAR2, or CLOB data type, the return type is VARCHAR2.

  • If the first expr is of the NCHAR or NVARCHAR2 data type, the return type is NVARCHAR2.

Examples

  • The following example compares the strings AC, BB, and C and returns the string with the greatest value.

    obclient> SELECT GREATEST('AC','BB','C') "MAX" FROM DUAL;
    +-----+
    | MAX |
    +-----+
    | C   |
    +-----+
    1 row in set
    
  • The following example compares the integer 1 and the strings 6 and 5.555 and returns the greatest value.

    obclient> SELECT GREATEST (1,'6','5.555') "MAX" FROM DUAL;
    +-----+
    | MAX |
    +-----+
    |   6 |
    +-----+
    1 row in set
    

Contact Us