1. What is the Oracle NUMBER
data type?
The NUMBER
data type is
used to store fixed and floating-point numbers. It allows both precision and
scale to be defined and supports very large or very small numbers.
2. What is the syntax of the NUMBER
data type?
NUMBER(p, s)
·
p
(precision): total number of
digits (1 to 38).
·
s
(scale): number of digits to the
right of the decimal point (–84 to 127).
Examples:
·
NUMBER(5,2)
can store
numbers like 123.45
.
·
NUMBER(3)
can store
integers up to 999
.
3. What happens if you omit precision and scale in NUMBER
?
If you define a column as just NUMBER
, Oracle allows
any number of digits up to the max (38 digits of precision) and the decimal
point can be anywhere.
salary NUMBER; -- Max flexibility, but can impact performance
4. What is the maximum and minimum value a NUMBER
can store?
·
Maximum: 9.999...E125
(38 9s)
·
Minimum (non-zero): 1.0E-130
·
Based on NUMBER(p,s)
, limits vary
with the defined p
and s
.
5. What is the difference between NUMBER
, NUMBER(p)
, and NUMBER(p,s)
?
·
NUMBER
– Unlimited
digits and scale (up to limits).
·
NUMBER(p)
– Fixed
precision; whole numbers only.
·
NUMBER(p,s)
– Fixed
precision and scale; used for exact numeric values like currency.
6. Does NUMBER
affect
performance in real-time systems?
Yes. Using unbounded NUMBER
(i.e., without
precision/scale) can cause slower performance due to internal conversions.
Always define precision and scale when possible to optimize storage and
performance.
7. Is NUMBER
a
fixed-precision or floating-point type?
It can act as both:
· Fixed-point when precision and scale are defined.
· Floating-point when used without limits.
8. What happens if a value exceeds the defined precision?
Oracle will raise a ORA-01438:
value larger than specified precision allowed
error during an
INSERT
or UPDATE
.
9. How does Oracle internally store NUMBER
?
Oracle stores numbers in a variable-length binary format, not ASCII or raw decimal. This allows efficient use of storage but requires internal conversion.
10. What are common use cases for different NUMBER
types?
·
NUMBER(5,2)
– Currency
(e.g., 999.99
)
·
NUMBER(10,0)
– Account IDs,
whole numbers
·
NUMBER
– Temporary or
dynamic numeric values
11. Can you use NUMBER
for identity
columns (auto-increment)?
Yes, in Oracle 12c+:
id NUMBER GENERATED BY DEFAULT AS IDENTITY
12. How does NUMBER
compare to FLOAT
or BINARY_FLOAT
?
·
NUMBER
– Exact
arithmetic, slower for scientific calculations.
·
BINARY_FLOAT/DOUBLE
– Faster for
approximate values, but may lose precision.
Use NUMBER
when accuracy
is critical (e.g., money), and BINARY_FLOAT
when speed
matters more (e.g., real-time telemetry).
13. How does Oracle handle rounding and truncation with NUMBER
?
If a value has more decimal places than allowed by scale:
· It is rounded unless explicitly truncated.
ROUND(123.456, 2)
→
123.46
TRUNC(123.456, 2)
→
123.45
14. What happens in real-time inserts if a value violates the NUMBER
constraints?
· Oracle throws an error, and the entire DML operation is rolled back.
· In high-volume inserts, these errors can severely affect throughput.
15. How can I avoid precision issues in real-time ETL jobs?
·
Use NUMBER(p,s)
explicitly.
· Validate input ranges before inserting.
· Use staging tables to catch bad data before loading into production tables.
16. How do NUMBER
fields affect
indexing performance?
Indexing on NUMBER(p,0)
is efficient.
Indexing floating or undefined precision NUMBER
columns can
increase index size and reduce performance.
17. Can a NUMBER
column be used
in partitioning or hashing?
Yes. Especially NUMBER(10,0)
is common in:
PARTITION BY HASH(account_id)
Avoid high-precision floating-point numbers for partition keys.
18. Is NUMBER
suitable for
time-series or telemetry data?
Partially. For telemetry (high-frequency
data), prefer BINARY_FLOAT
or BINARY_DOUBLE
for
performance, unless exact values are critical.
19. How does Oracle handle arithmetic between different NUMBER
precisions?
Oracle promotes numbers to the higher precision and scale during operations, which can cause overflow or truncation errors if not handled properly.
20. What are best practices for using NUMBER
in real-time
applications?
· Always define precision and scale.
·
Avoid NUMBER
without
precision in OLTP systems.
·
Use numeric constraints (CHECK
) to enforce
valid ranges.
· Use bind variables to reduce parsing and improve performance.
·
Use appropriate data types: don’t use NUMBER
when INTEGER
or BINARY_FLOAT
is better
suited.
Would you like a downloadable cheat sheet or table summary of these FAQs?
No comments:
Post a Comment