MAX

The MAX scalar function returns the maximum value in a set of values.

Read syntax diagram
                  .-------------.     
                  V             |     
>>-MAX(expression---,expression-+-)----------------------------><

The schema is SYSIBM.

The arguments must be compatible. For more information on compatibility, refer to the compatibility matrix in Table 1. All but the first argument can be parameter markers. There must be two or more arguments.

Each argument must be an expression that returns a value of any built-in data type other than a CLOB, DBCLOB, BLOB, ROWID, or XML.

Start of changeCharacter string arguments and binary string arguments cannot have a length attribute greater than 32704, and graphic string arguments cannot have a length attribute greater than 16352.End of change

The arguments are evaluated in the order in which they are specified. The result of the function is the maximum argument value.

The result can be null; if any argument is null, the result is the null value.

The selected argument is converted, if necessary, to the attributes of the result. The attributes of the result are determined using the Rules for result data types. If the MAX function has more than two arguments, the rules are applied to the first two arguments to determine a candidate result type. The rules are then applied to that candidate result type and the third argument to determine another candidate result type. This process continues until all arguments are analyzed and the final result type and CCSID is determined.

GREATEST can be specified as a synonym for MAX.

Example 1: Assume the host variable M1 is a DECIMAL(2,1) host variable with a value of 5.5, host variable M2 is a DECIMAL(3,1) host variable with a value of 4.5, and host variable M3 is a DECIMAL(3,2) host variable with a value of 6.25. The following function returns the value 6.25.
    MAX(:M1,:M2,:M3) 
Example 2: Assume the host variable M1 is a CHAR(2) host variable with a value of 'AA', host variable M2 is a CHAR(3) host variable with a value of 'AA ', and host variable M3 is a CHAR(4) host variable with a value of 'AA A'. The following function returns the value 'AA A'.
    MAX(:M1,:M2,:M3)