Z
Z
zencd2020-10-28 23:01:18
Oracle
zencd, 2020-10-28 23:01:18

Why does multiplication by a constant cause an overflow in PL/SQL?

Here are three seemingly identical expressions, but on the latest Oracle 12c PL/SQL crashes with the error "ORA-01426: numeric overflow. Evaluation of an value expression causes an overflow/underflow". Why is that?

declare
    n number(38,0);
    mul number(38,0) := 100;
begin
    n := 2255543300; -- ok
    n := 22555433 * mul; -- ok
    n := 22555433 * 100; -- numeric overflow
end;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
idShura, 2020-10-29
@zencd

n := 22555433 * 100;
A calculation with two PLS_INTEGER values ​​that is out of range of PLS_INTEGER throws an overflow exception, even if you assign the result to the NUMBER data type.
Here Tom Kyte analyzes this issue in detail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question