Oracle data types define how values are stored, validated, and processed in a table column.
Oracle groups data types into character (CHAR, VARCHAR2, CLOB), numeric (NUMBER, FLOAT, BINARY_FLOAT), date‐time (DATE, TIMESTAMP, INTERVAL), and binary (RAW, BLOB). Each type controls storage format, valid operations, and index behavior, so choosing correctly prevents conversion overhead.
VARCHAR2 is ideal for variable-length strings up to 32,767 bytes and is the default choice. CHAR pads to fixed length and suits codes like country_id. Use CLOB only for text beyond 32 KB to avoid LOB management overhead.
NUMBER(precision, scale) offers exact arithmetic—critical for prices and quantities. FLOAT and BINARY_FLOAT use IEEE binary precision, trading rounding accuracy for speed. Prefer NUMBER for financial figures and FLOAT only for scientific or large-range values.
DATE stores date and time to the second without fractional seconds or time zone. TIMESTAMP adds fractional seconds; TIMESTAMP WITH TIME ZONE keeps session-independent offsets—essential for multi-region order tracking.
Yes. Enable MAX_STRING_SIZE = EXTENDED (requires restart) to push VARCHAR2 and NVARCHAR2 to 32,767 bytes. Otherwise Oracle silently limits them to 4,000 bytes, forcing you to use CLOB for larger values.
Specify each column’s data type and optional precision, scale, length, or time zone. Constraints like NOT NULL or DEFAULT follow the type definition.
Match data type to real-world domain; avoid generic VARCHAR2 for numbers or dates. Declare precision and scale on NUMBER to help Oracle choose efficient storage. Use TIMESTAMP WITH TIME ZONE for cross-region apps. Store large free text in CLOB, not VARCHAR2.
Mistake 1 – Using VARCHAR2 for numeric IDs: Forces implicit conversions in joins and slows indexes. Fix by declaring NUMBER(10) or the smallest suitable integer size.
Mistake 2 – Ignoring time zones: Storing shipment times in DATE causes confusion across regions. Fix by switching to TIMESTAMP WITH TIME ZONE or storing offset separately.
CREATE TABLE Orders (
id NUMBER(10) PRIMARY KEY,
customer_id NUMBER(10) NOT NULL,
order_date TIMESTAMP WITH TIME ZONE DEFAULT SYSTIMESTAMP,
total_amount NUMBER(12,2) CHECK (total_amount >= 0)
);
Query ALL_TAB_COLUMNS
to view existing column data types and use DESC table_name
for quick checks.
Yes, when the database character set is AL32UTF8 or UTF8. No extra codepage column is necessary.
NUMBER supports up to 38 digits of precision, with scale from ‑84 to 127, letting you store anything from micro-units to astronomical figures.
Oracle raises ORA-01438 at insert time, rejecting the row. Increase precision/scale or ROUND before insert.
Yes, if the database character set is AL32UTF8 or UTF8. No special column setting is required.
NUMBER supports up to 38 digits of precision and scales from −84 to 127.
Oracle throws ORA-01438 and rejects the insert or update. Increase precision or round the value first.