The
INTEGER function returns an integer representation of a number, a
string representation of a number, a date value, or a time value.
Numeric to Integer:
>>-+-INTEGER-+--(--numeric-expression--)-----------------------><
'-INT-----'
String to Integer:
>>-+-INTEGER-+--(--string-expression--)------------------------><
'-INT-----'
Date to Integer:
>>-+-INTEGER-+--(--date-expression--)--------------------------><
'-INT-----'
Time to Integer:
>>-+-INTEGER-+--(--time-expression--)--------------------------><
'-INT-----'
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. The fractional part of the argument is truncated.
If the whole part of the argument is not within the range of integers,
an error is returned (SQLSTATE 22003).
String to Integer:
- string-expression
- An expression that returns a value that
is a character-string or Unicode graphic-string representation of
a number with a of 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 INTEGER). 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 integers,
an error is returned (SQLSTATE 22003). The data type of string-expression must
not be CLOB or DBCLOB (SQLSTATE 42884).
Date to Integer:
- date-expression
- An expression that returns a value of the DATE data type. The
result is an INTEGER value representing the date as yyyymmdd.
Time to Integer:
- time-expression
- An expression that returns a value of the TIME data type. The
result is an INTEGER value representing the time as hhmmss.
The result of the function is a large integer. If the
argument can be null, the result can be null; if the argument is null,
the result is the null value.
Note: The CAST specification
should be used to increase the portability of applications. For more
information, see "CAST specification".
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 employee number (EMPNO). The list should
be in descending order of the calculated value.
SELECT INTEGER (SALARY / EDLEVEL), SALARY, EDLEVEL, EMPNO
FROM EMPLOYEE
ORDER BY 1 DESC
- Example 2: Using the EMPLOYEE table, select the EMPNO column
in integer form for further processing in the application.
SELECT INTEGER(EMPNO) FROM EMPLOYEE
- Example 3: Assume that the column BIRTHDATE (whose data
type is DATE) has an internal value equivalent to '1964-07-20'.
INTEGER(BIRTHDATE)
results
in the value 19 640 720.
- Example 4: Assume that the column STARTTIME (whose data
type is TIME) has an internal value equivalent to '12:03:04'.
INTEGER(STARTTIME)
results
in the value 120 304.