SMALLINT scalar function

The SMALLINT function returns a small integer (a binary integer with a precision of 15 bits) representation of a value of a different data type.

Numeric to SMALLINT

Read syntax diagramSkip visual syntax diagramSMALLINT(numeric-expression)

String to SMALLINT

Read syntax diagramSkip visual syntax diagramSMALLINT(string-expression)

Boolean to SMALLINT

Read syntax diagramSkip visual syntax diagram SMALLINT ( boolean-expression )

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. The fractional part of the argument is truncated. If the whole part of the argument is not within the range of small integers, an error is returned (SQLSTATE 22003).

String to SMALLINT
string-expression
An expression that returns a value that is a character-string or Unicode graphic-string representation of a number with a length not greater than the maximum length of a character constant.

The result is the same number that would result from CAST(string-expresssion AS SMALLINT). Leading and trailing blanks are eliminated and the resulting string must conform to the rules for forming an integer, decimal, floating-point, or decimal floating-point constant (SQLSTATE 22018). If the whole part of the argument is not within the range of small integers, an error is returned (SQLSTATE 22003). The data type of string-expression must not be CLOB or DBCLOB (SQLSTATE 42884).

Boolean to SMALLINT
boolean-expression
An expression that returns a Boolean value (TRUE or FALSE). The result is either 1 (for TRUE) or 0 (for FALSE).

Result

The result of the function is a small integer. If the argument can be null, the result can be null; if the argument is null, the result is the null value.

Notes

  • Increasing portability of applications: If the first argument is numeric, or if the first argument is a string and the length argument is specified, use the CAST specification instead of this function to increase the portability of your applications.

Examples

  • Example 1: Using the EMPLOYEE table, select a list containing salary (SALARY) divided by education level (EDLEVEL). Truncate any decimal in the calculation. The list should also contain the values used in the calculation and the employee number (EMPNO).
       SELECT SMALLINT(SALARY / EDLEVEL), SALARY, ESDLEVEL, EMPNO     
         FROM EMPLOYEE
  • Example 2: The following statement returns the value 1 of data type SMALLINT.
       values SMALLINT(TRUE)
  • Example 3: The following statement returns the value 0 of data type SMALLINT.
       values SMALLINT(3>3)