Numbers in DB2 for z/OS are not one-size-fits-all. Counters, money, scientific measurements, and surrogate keys need different numeric types. This overview introduces the family, then explains precision, scale, overflow, conversion, and promotion so the detailed type pages (starting with SMALLINT) make sense.
Db2 groups numeric storage into several families:
| Type | Range (approx.) | Storage |
|---|---|---|
| SMALLINT | −32768 … 32767 | 2 |
| INTEGER | −2,147,483,648 … 2,147,483,647 | 4 |
| BIGINT | about ±9.2e18 | 8 |
| DECIMAL(p,s) | up to 31 digits | INTEGER(p/2)+1 |
| DECFLOAT(16/34) | very large decimal float ranges | 9 / 17 |
Rule of thumb for beginners: use INTEGER or BIGINT for whole counts and keys; use DECIMAL for money and exact fractions; use floating types only when approximation is acceptable. SMALLINT saves space for small codes and flags when the range is guaranteed.
Precision is the total number of digits a decimal value can hold. In DECIMAL(9,2), precision is 9—so at most nine digits altogether. Binary integers do not use DECIMAL-style precision attributes; their “precision” is fixed by the type (SMALLINT is described as a binary integer with 15-bit precision in the manuals).
12345-- Precision 9, scale 2 → max like 9999999.99 CREATE TABLE APP.PRICES ( SKU CHAR(8) NOT NULL, PRICE DECIMAL(9,2) NOT NULL );
Choosing precision too small causes overflow on insert. Choosing precision far too large wastes storage (packed decimal length grows with precision) and can affect some comparisons and displays. Size columns to real business limits plus a little headroom.
Scale is the number of digits to the right of the decimal point. In DECIMAL(9,2), scale 2 means cents for currency in many shops. Scale 0 means an integer stored in decimal form. Scale cannot exceed precision.
12VALUES DECIMAL(123.456, 9, 2); -- becomes 123.46 (rounding rules apply) VALUES DECIMAL(123.456, 9, 0); -- whole number decimal
When converting from a higher scale to a lower scale, fractional digits are rounded or truncated per Db2 rules for that operation. Design scale to match the business unit—do not store dollars with scale 0 if you need cents.
Numeric overflow occurs when a value cannot be represented in the target or result type. Classic examples:
12345-- Overflow risk: SMALLINT max 32767 INSERT INTO APP.FLAGS (CODE) VALUES (40000); -- fails if CODE is SMALLINT -- Safer intermediate typing SELECT CAST(A AS BIGINT) * CAST(B AS BIGINT) FROM APP.NUMS;
Unlike some programming languages that wrap on overflow, Db2 SQL typically raises an error. That protects data integrity. Watch intermediate results in expressions—not only the final column type.
Numeric conversion changes a value from one numeric type to another during assignment, CAST, or expression evaluation. Conversion may:
1234SELECT CAST(SMALLINT_COL AS INTEGER), CAST(INT_COL AS DECIMAL(11,2)), CAST(DEC_COL AS DOUBLE) FROM APP.SAMPLE;
String↔numeric conversion is a related topic on the casting page. Prefer CAST when reading external character files into numeric columns so bad tokens fail clearly.
Numeric promotion follows the precedence list used in function resolution and related contexts: SMALLINT toward INTEGER, BIGINT, decimal, real, double, DECFLOAT; and similarly for other starting types. Promotion helps Db2 pick a function overload or treat arguments as a common wider type.
In mixed arithmetic, result types follow detailed operation rules in the SQL Reference (not always “whatever you hoped”). When exact scale matters, CAST operands before calculating.
The next pages walk each major type with ranges, host-variable mapping, and overflow notes—starting with SMALLINT.
Numeric types are different sized jars for numbers. A tiny jar (SMALLINT) only holds small counts. A bigger jar (INTEGER/BIGINT) holds huge whole counts. A measuring jar with marks for pennies (DECIMAL) holds exact money. A fuzzy science jar (FLOAT) holds “about this many.” Precision is how many digit stickers fit on the jar. Scale is how many stickers sit after the decimal point. Overflow is trying to pour too much into a small jar—Db2 spills and complains instead of secretly overflowing onto the floor.
1. What is precision for a DECIMAL number?
2. What is scale?
3. Which type is a 2-byte binary integer?
4. What is numeric overflow?
5. In promotion, SMALLINT can move toward: