Not every string is single-byte text. Graphic types hold double-byte characters; binary types hold raw bytes. This page introduces GRAPHIC, VARGRAPHIC, graphic and Unicode graphic data, BINARY, and VARBINARY—and when to prefer their LOB cousins.
When columns contain double-byte character set (DBCS) characters, you can define them as graphic data or as mixed character data. Graphic types are GRAPHIC, VARGRAPHIC, and DBCLOB.
| Type | Role |
|---|---|
| GRAPHIC(n) | Fixed DBCS string, n double-byte characters (≤127) |
| VARGRAPHIC(n) | Varying DBCS string; max depends on page size (≤16352) |
| DBCLOB(n) | Graphic LOB for very large DBCS text |
GRAPHIC(n) — fixed-length graphic string of n double-byte characters. n must be greater than 0 and less than 128; default length is 1.
VARGRAPHIC(n) — varying-length graphic string. Maximum n depends on table space page size and can be up to 16352 double-byte characters. Like VARCHAR, VARGRAPHIC saves space when lengths vary but costs a length prefix and variable-row processing. IBM’s guidance: prefer GRAPHIC unless savings are significant; generally avoid VARGRAPHIC(n) unless n is at least about 18 double-byte characters (36 bytes).
12345CREATE TABLE PRODUCT_JA ( SKU CHAR(10) NOT NULL, NAME_DBCS VARGRAPHIC(40) NOT NULL, PRIMARY KEY (SKU) );
If all characters are DBCS, use graphic types. Mixed-data CHAR/VARCHAR/CLOB with MIXED can hold SBCS and DBCS together; for pure SBCS runs inside mixed data you may save space versus treating everything as graphic—but pure DBCS workloads belong on graphic columns.
Multinational applications often use Unicode. Graphic Unicode data is commonly associated with UTF-16 (for example CCSID 1200). SQL provides Unicode graphic hex literals (such as UX\'....\') and application variables aligned to graphic Unicode encodings.
Character conversion between encodings can be automatic and invisible when it succeeds—but designing columns and CCSID from the start avoids silent substitution characters. Prefer Unicode when one table must serve many geographies.
123-- Conceptual: Unicode graphic hex literal (UTF-16 code units) SELECT UX'004100420043' FROM SYSIBM.SYSDUMMY1; -- Represents graphic Unicode characters (example pattern for ABC)
Exact literal forms and host-variable declarations depend on language and CCSID setup—treat this as vocabulary, then follow your shop’s Unicode standards.
Binary strings contain bytes that do not represent characters. Types include BINARY, VARBINARY, and BLOB.
| Type | Role |
|---|---|
| BINARY(n) | Binary string of n bytes (1–255) |
| VARBINARY(n) | Varying binary string; max ≤32704 (page dependent) |
| BLOB(n) | Binary LOB for very large byte payloads |
BINARY(n) — binary string of length n bytes (1–255; default 1). Think of it as the binary analogue of short fixed CHAR.
VARBINARY(n) — varying-length binary string; maximum n depends on page size and can be up to 32704. Use for moderate binary values (keys, hashes, small opaque payloads). Use BLOB when sizes grow into megabytes or more.
123456CREATE TABLE DEVICE ( DEVICE_ID INTEGER NOT NULL, MAC_ADDR BINARY(6) NOT NULL, FINGERPRINT VARBINARY(64) NOT NULL, PRIMARY KEY (DEVICE_ID) );
Historically, CHAR/VARCHAR FOR BIT DATA stored non-character bytes in character-typed columns. BINARY/VARBINARY express the intent more clearly. New designs should prefer binary types unless compatibility with old tables requires FOR BIT DATA.
Binary-string constants use forms such as BX\'hex\'. Do not confuse them with X\'hex\' character hex constants—they are different types and not interchangeable.
Mixing families in comparisons requires casts and careful CCSID planning. Keep keys and join columns in compatible types.
Regular letters fit in a small pencil case (CHAR). Some alphabets need wider pencils—that case is graphic data. A sealed bag of beads that are not letters at all is binary data: count beads (bytes), don’t read them as words. Big bags of beads are BLOBs; big wide-pencil books are DBCLOBs.
1. GRAPHIC(n) stores:
2. VARGRAPHIC differs from GRAPHIC mainly by:
3. Binary strings (BINARY / VARBINARY) contain:
4. When all characters are DBCS, IBM recommends:
5. VARBINARY maximum length is on the order of: