NUMBER
- Used to store numeric values (integers and decimals).
- Syntax: NUMBER(p,s) — where p = precision, s = scale.
- Can store very large or very small numbers.
- Defaults to floating-point if precision and scale are not specified.
- Supports arithmetic operations directly.
- Precision can be up to 38 digits.
- Scale can be negative for rounding.
- Commonly used for IDs, quantities, prices, etc.
- Indexable and supports constraints.
- Compatible with most numeric SQL functions.
CHAR
- Fixed-length character data type.
- Padding with spaces if input is shorter than defined length.
- Syntax: CHAR(n) — n = number of characters.
- Max size: 2000 bytes.
- Useful for storing codes (e.g., country codes).
- Case-sensitive.
- Comparisons consider trailing spaces.
- Slower than VARCHAR2 for varying-length text.
- Can be indexed.
- Stores character data based on the database character set.
VARCHAR2
- Variable-length character data.
- Syntax: VARCHAR2(n) — n = max number of characters.
- Max size: 4000 bytes (extended up to 32767 in some configurations).
- More efficient than CHAR for dynamic-length text.
- Does not pad trailing spaces.
- Common for names, addresses, descriptions, etc.
- Case-sensitive.
- Can be indexed.
- Supports functions like UPPER, LOWER, SUBSTR.
- Most commonly used string type in Oracle.
NCHAR
- Fixed-length Unicode character type.
- Stores data in the national character set.
- Syntax: NCHAR(n) — stores exactly n characters.
- Max size: 2000 bytes.
- Good for multilingual data storage.
- Pads with Unicode spaces if input is shorter.
- Slower than CHAR due to Unicode handling.
- Case-sensitive and locale-aware.
- Can be indexed.
- Useful for global applications.
DATE
- Stores date and time (down to seconds).
- Default format: 'DD-MON-YY' (can vary by NLS settings).
- Range: Jan 1, 4712 BC to Dec 31, 9999 AD.
- Includes time (HH24:MI:SS).
- Can use functions like SYSDATE, ADD_MONTHS, LAST_DAY.
- Commonly used for timestamps and scheduling.
- Indexable.
- Supports arithmetic (e.g., date1 - date2 gives number of days).
- Time zone not stored.
- Most basic temporal type in Oracle.
TIMESTAMP
- Extends DATE to include fractional seconds.
- Syntax: TIMESTAMP [(fractional_seconds_precision)].
- Default fractional precision is 6 digits.
- No time zone info stored.
- Useful when high-precision time is required.
- Can compare and perform arithmetic like DATE.
- Supports functions like CURRENT_TIMESTAMP.
- Indexable.
- Can be cast to/from DATE.
- Suitable for detailed event logging.
TIMESTAMP WITH TIME ZONE
- Adds time zone to the TIMESTAMP data.
- Syntax: TIMESTAMP WITH TIME ZONE.
- Stores exact point in time globally.
- Time zone offset saved with data.
- Good for global systems (e.g., booking platforms).
- Handles daylight saving time.
- Supports CURRENT_TIMESTAMP with time zone.
- Can convert to/from local time.
- Allows comparing times across zones.
- Used in distributed systems and audits.
TIMESTAMP WITH LOCAL TIME ZONE
- Stores time in database time zone, shows in user's local time zone.
- Time zone info is not stored permanently.
- Useful when display should reflect user's location.
- Ideal for user-facing applications.
- Converted automatically on insert/retrieval.
- Prevents confusion due to time zone differences.
- Not suitable if you need to know original time zone.
- Reduces data size vs. WITH TIME ZONE.
- Indexable.
- Helps maintain uniform storage with flexible display.
INTERVAL YEAR TO MONTH
- Stores a duration in years and months.
- Syntax: INTERVAL YEAR (p) TO MONTH.
- Used to represent elapsed time (e.g., 2 years 3 months).
- Cannot be added directly to TIMESTAMP.
- Works with ADD_MONTHS, NUMTODSINTERVAL, etc.
- Precise for billing cycles or age calculations.
- Can be positive or negative.
- Not affected by varying days in months.
- Useful for contracts and subscriptions.
- Not timezone-aware.
INTERVAL DAY TO SECOND
- Stores a duration in days, hours, minutes, seconds.
- Syntax: INTERVAL DAY (p1) TO SECOND (p2).
- Useful for representing precise durations.
- Can include fractional seconds.
- Often used for tracking elapsed time.
- Supports date arithmetic.
- Positive or negative durations supported.
- Works with NUMTODSINTERVAL.
- Great for measuring performance or delays.
- Time zone-independent.
RAW
- Stores binary or byte data (not interpreted as characters).
- Syntax: RAW(n) — n = number of bytes.
- Max size: 2000 bytes.
- Used for UUIDs, keys, encryption data.
- Not human-readable.
- Not converted between systems.
- Cannot be indexed using B-tree.
- Supports HEXTORAW, RAWTOHEX.
- Works with PL/SQL collections.
- Use when exact binary values must be preserved.
LONG RAW
- Like RAW, but supports larger binary data.
- Max size: 2 GB.
- Deprecated in favor of BLOB.
- Used for legacy systems storing binary data.
- Cannot be indexed.
- Only one LONG RAW column per table.
- Not supported in many SQL functions.
- Harder to work with compared to LOBs.
- Stored out-of-line in large objects area.
- Consider migrating to BLOB.
CLOB (Character LOB)
- Stores large blocks of text (up to 4 GB).
- Supports character data (based on DB charset).
- Suitable for documents, descriptions, XML, etc.
- Supports streaming reads/writes in PL/SQL.
- Stored out-of-line by default.
- Can be indexed (with limitations).
- Supports functions like DBMS_LOB.
- Slower than VARCHAR2 for short text.
- Often used in web apps and APIs.
- Requires special handling in SQL queries.
NCLOB (National CLOB)
- Like CLOB, but stores Unicode characters.
- Useful for multilingual large text.
- Stored using national character set.
- Max size: 4 GB.
- Slower than CLOB due to Unicode.
- Supports full LOB operations.
- Used in internationalized applications.
- Not all clients support NCLOB well.
- Requires special care for charset conversions.
- Rarely used unless multi-language is essential.
BLOB (Binary LOB)
- Stores large binary data (images, videos, etc.).
- Max size: 4 GB.
- Not human-readable.
- Can be accessed via DBMS_LOB.
- Stored out-of-line.
- Useful for file storage in DB.
- Supports streaming and chunking.
- Cannot be directly queried like text.
- Often used with base64 encoding in apps.
- Performance depends on LOB storage options.
BFILE
- Stores reference to a binary file in the OS.
- File is outside the database.
- Read-only access.
- Max size: 4 GB.
- Useful for external file management.
- Needs directory object defined in DB.
- Faster access than BLOB for static files.
- Not backed up with DB by default.
- Security must be managed at OS level.
- Great for integration with file systems.
ROWID
- Represents physical address of a row in a table.
- Unique within a table.
- Fastest way to access a row.
- Format is block.row.file.
- Changes if row is moved.
- Used internally by Oracle.
- Can be selected in queries.
- Helps in debugging and performance tuning.
- Cannot be used across tables.
- Not human-readable.
UROWID (Universal ROWID)
- Extends ROWID to support index-organized tables (IOTs).
- Can represent logical row addresses.
- Useful when physical ROWID doesn't exist.
- Useful in distributed databases.
- Format is longer than ROWID.
- Can reference rows in foreign systems.
- Can be stored as column data.
- Suitable for object-relational features.
- Human-readable (to an extent).
- Preferred when ROWID isn't sufficient.
XMLTYPE
- Used to store and query XML data.
- Can store XML as CLOB or object-relational.
- Enables XPath and XQuery support.
- Ideal for web services, APIs, configs.
- Supports indexing with XML indexes.
- Can validate against XML Schema.
- Can extract parts of XML using EXTRACTVALUE, XMLTABLE.
- Supported in PL/SQL and SQL.
- Useful for structured documents.
- Performance depends on storage model (binary vs. structured).
No comments:
Post a Comment