Declares literal strings of integer numbers in an expression.
Syntax
[ + | - ] n
- +, -
- An optional sign.
- n
- Any valid integer.
Components of Integer Literals
Integer literals consist of an optional sign followed by a sequence of digits. Spaces and new line characters are not allowed in a literal except after the optional sign.
Integer Literal Data Types
The data type of an integer literal is determined by the range of the literal value. The type used is the smallest that can contain the value.
IF an integer literal fits in this range of values … | THEN the data type of the integer literal is … |
---|---|
-128 to 127 | BYTEINT |
-32768 to -129 | SMALLINT |
128 to 32767 | |
-2147483648 to -32769 | INTEGER |
32768 to 2147483647 |
A numeric literal that is outside the range of the INTEGER type is assigned to the DECIMAL type, unless it is outside the range of values that a DECIMAL type can represent. For more information, see Decimal Literals.
Numeric literals are not assigned to the BIGINT type. If you need a numeric literal that is outside the range of the INTEGER type to be of a type other than DECIMAL, you can explicitly cast the literal to the desired type. For example, you can use the CAST function to explicitly cast a numeric literal to BIGINT:
SELECT ProdID FROM PartsTbl WHERE CustID = CAST(9876543210 AS BIGINT);
Examples: Integer Literals
The following numbers are examples of integer literals.
12 0 -5
Related Topics
FOR information on … | SEE … |
---|---|
BYTEINT data types | BYTEINT Data Type. |
SMALLINT data types | SMALLINT Data Type. |
INTEGER data types | INTEGER Data Type. |