SMALLINT scalar function
The SMALLINT function returns a small integer representation either of a number or of a string representation of a number.
Numeric to Smallint:
String to Smallint:
The schema is SYSIBM.
Numeric to Smallint
- 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 small integer column or variable. If the whole part of the argument is not within the range of small integers, an error occurs. If present, the decimal part of the argument is truncated.
String to Smallint
- string-expression
- An expression that returns a value of character or graphic string (except a CLOB or DBCLOB) with a length attribute that is not greater than 255 bytes for a character string or 127 for a graphic string. 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 SMALLINT). Leading and trailing blanks are eliminated and the resulting string must conform to the rules for forming an SQL integer constant.
The result of the function is a small integer.
The result can be null; if the argument is null, the result is the null value.
Notes
- Syntax alternatives:
- To increase the portability of applications, use the CAST specification. For more information, see CAST specification.
Examples
- Example 1:
- Using sample table DSN8C10.EMP, find the average education level (EDLEVEL) of the employees in department 'A00'. Round the result to the nearest full education level.
Assuming that the five employees in the department have education levels of '19', '18', '14', '18', and '14', the result is '17'.SELECT SMALLINT(AVG(EDLEVEL)+.5) FROM DSN8C10.EMP WHERE DEPT = 'A00';
