INTEGER or INT

The INTEGER function returns an integer representation of either a number or a character string or graphic string representation of an integer.

Numeric to Integer:

Read syntax diagram
>>-+-INTEGER-+-(numeric-expression)----------------------------><
   '-INT-----'                        

String to Integer:

Read syntax diagram
>>-+-INTEGER-+-(string-expression)-----------------------------><
   '-INT-----'                       

The schema is SYSIBM.

Numeric to Integer
numeric-expression
An expression that returns a value of any built-in numeric data type.

The result is the same number that would occur if the argument were assigned to a large integer column or variable. If the whole part of the argument is not within the range of large integers, an error occurs. The fractional part of the argument is truncated.

String to Integer
string-expression
An expression that returns a value of a character or graphic string (except a CLOB or DBCLOB) with a length attribute that is not greater than 255 bytes. The string must contain a valid string representation of a number.

The result is the same number that would result from CAST(string-expression AS INTEGER). Leading and trailing blanks are eliminated and the resulting string must conform to the rules for forming an integer constant. If the whole part of the argument is not within the range of large integers, an error is returned.

The result of the function is a large integer.

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

Recommendation: To increase the portability of applications, use the CAST specification. For more information, see CAST specification.
Example 1: Using sample table DSN8A10.EMP, find the average salary of the employees in department A00, rounding the result to the nearest dollar.
   SELECT INTEGER(AVG(SALARY)+.5)
     FROM DSN8A10.EMP
     WHERE WORKDEPT = 'A00';
Example 2: Using sample table DSN8A10.EMP, select the EMPNO column, which is defined as CHAR(6), in integer form.
   SELECT INTEGER(EMPNO)
     FROM DSN8A10.EMP;