INTEGER (synonym INT) is Db2 for z/OS’s standard 4-byte binary integer type. It stores whole numbers from about −2.1 billion to +2.1 billion and appears everywhere: surrogate keys, counters, status codes, and quantities that do not need fractional digits. This page covers range and storage, when to choose INTEGER, overflow and promotion, and COBOL host-variable mapping notes.
An INTEGER value is a binary integer with 31 bits of magnitude plus a sign. Db2 stores each INTEGER column value in 4 bytes. Unlike DECIMAL, there is no separate precision/scale parameter—the type itself fixes the range.
| Item | Detail |
|---|---|
| SQL names | INTEGER or INT |
| Storage | 4 bytes |
| Minimum | −2,147,483,648 |
| Maximum | +2,147,483,647 |
| Category | Exact binary integer (not floating-point) |
123456CREATE TABLE ORDER_LINE ( ORDER_ID INTEGER NOT NULL, LINE_NO INTEGER NOT NULL, QTY INTEGER NOT NULL, PRIMARY KEY (ORDER_ID, LINE_NO) );
Integer literals in SQL are written as numbers without quotes: 42, -1000. Quoted '42' is a character string that may convert implicitly in some contexts—but clear code uses true numeric literals for numeric columns.
Choose INTEGER when:
IBM documentation advises: for integer values, use SMALLINT, INTEGER, or BIGINT—not DECIMAL. DECIMAL is for fixed-point numbers with a fractional scale (money, percentages with fixed digits). Using DECIMAL(9,0) as a fake integer wastes clarity and can surprise you with packed-decimal behavior and host mappings.
If an expression or assignment produces a value outside the INTEGER range, Db2 signals numeric overflow. Examples include multiplying two large INTEGER values into a temporary that still expects INTEGER, or casting a BIGINT that is too large down to INTEGER.
1234567-- Risky if QTY and UNIT_FACTOR are both large INTEGER values SELECT QTY * UNIT_FACTOR AS EXTENDED FROM ORDER_LINE; -- Safer when the product may exceed INTEGER: promote explicitly SELECT BIGINT(QTY) * BIGINT(UNIT_FACTOR) AS EXTENDED FROM ORDER_LINE;
Overflow is a run-time data error, not a syntax error. Test boundary values when columns feed calculations.
When SQL mixes numeric types, Db2 applies promotion and conversion rules so operands share a result type. Mixing INTEGER with DECIMAL or floating-point can change the result type and rounding behavior. Mixing INTEGER with BIGINT often promotes toward BIGINT. Learn the exact precedence tables later; as a beginner rule: do not assume the result of mixed arithmetic stays INTEGER.
123456789-- INTEGER column compared to a typed literal SELECT * FROM ORDER_LINE WHERE QTY > 100; -- Cast when moving between integer sizes deliberately SELECT CAST(LINE_NO AS SMALLINT) AS LINE_SMALL FROM ORDER_LINE WHERE LINE_NO <= 32767;
In embedded SQL, host variables carry INTEGER values between COBOL and Db2. A typical fullword mapping looks like:
1234567891001 WS-ORDER-ID PIC S9(9) USAGE COMP. 01 WS-QTY PIC S9(9) USAGE COMP-5. EXEC SQL SELECT QTY INTO :WS-QTY FROM ORDER_LINE WHERE ORDER_ID = :WS-ORDER-ID AND LINE_NO = 1 END-EXEC.
Mismatching a Db2 INTEGER column with a halfword SMALLINT host variable (or vice versa) can cause truncation or unexpected SQLCODEs. Keep the host declaration aligned with the column type.
INTEGER is a special box that only holds whole toys—no half toys. The box is medium-sized: it can hold a huge pile, but not an endless pile. If you try to stuff in more toys than the box allows, it overflows and complains. Smaller boxes (SMALLINT) hold fewer toys; bigger boxes (BIGINT) hold more. Money with coins usually needs a different kind of box (DECIMAL) that understands fractional parts.
1. How many bytes does a Db2 INTEGER column occupy?
2. What is the approximate range of INTEGER?
3. What is another SQL name for INTEGER in Db2?
4. When might INTEGER be a better choice than DECIMAL for whole numbers?
5. A common COBOL mapping for INTEGER is: