Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-30 · container image gvenzl/oracle-free:23-slim
ORA-01426 means the result of a calculation does not fit the type it is computed in. In PL/SQL this is usually PLS_INTEGER, whose maximum is 2147483647 (POWER(2, 31) - 1). In SQL it can be NUMBER itself, when the value is astronomically large.
The error does not say which variable overflowed. In PL/SQL, the ORA-06512: at line N under it points to the line with the calculation. Below are the three cases we reproduced on Oracle 26ai Free, each with the fixed code actually run.
01Summing into a PLS_INTEGER variable that passes 2147483647
A loop adds amount from two rows (1500000000 and 900000000) into v_total PLS_INTEGER. The total is 2400000000, and the block fails with ORA-01426 at line 5, the v_total := v_total + r.amount; line.
SELECT SUM(amount), POWER(2, 31) - 1 showed 2400000000 against a maximum of 2147483647. After changing the declaration to v_total NUMBER, the same loop printed total = 2400000000.
Setup
CREATE TABLE sales (id NUMBER PRIMARY KEY, amount NUMBER);
INSERT INTO sales VALUES (1, 1500000000);
INSERT INTO sales VALUES (2, 900000000);
COMMIT;Table created.
1 row created.
1 row created.
Commit complete.SET SERVEROUTPUT ON
DECLARE
v_total PLS_INTEGER := 0;
BEGIN
FOR r IN (SELECT amount FROM sales ORDER BY id) LOOP
v_total := v_total + r.amount;
END LOOP;
DBMS_OUTPUT.PUT_LINE('total = ' || v_total);
END;
/DECLARE
*
ERROR at line 1:
ORA-01426: numeric overflow
ORA-06512: at line 5
ORA-06512: at line 5
Help: https://docs.oracle.com/error-help/db/ora-01426/SELECT SUM(amount) AS total, POWER(2, 31) - 1 AS pls_integer_max FROM sales; TOTAL PLS_INTEGER_MAX
---------- ---------------
2400000000 2147483647
1 row selected.Use PLS_INTEGER only for counters and indexes. For amounts and totals, NUMBER is the safe choice.
SET SERVEROUTPUT ON
DECLARE
v_total NUMBER := 0;
BEGIN
FOR r IN (SELECT amount FROM sales ORDER BY id) LOOP
v_total := v_total + r.amount;
END LOOP;
DBMS_OUTPUT.PUT_LINE('total = ' || v_total);
END;
/total = 2400000000
PL/SQL procedure successfully completed.02Multiplying two PLS_INTEGER values, even when the result variable is NUMBER
v_amount := v_qty * v_price; with v_qty = 50000 and v_price = 60000, both PLS_INTEGER, fails with ORA-01426 at line 6. The result variable v_amount is NUMBER, but the multiplication itself is done in PLS_INTEGER, and 3000000000 overflows before it is ever assigned.
The same 50000 * 60000 in SQL returned 3000000000 without error, because SQL computes it as NUMBER. In PL/SQL, CAST(v_qty AS NUMBER) * v_price made the calculation NUMBER and printed amount = 3000000000.
SET SERVEROUTPUT ON
DECLARE
v_qty PLS_INTEGER := 50000;
v_price PLS_INTEGER := 60000;
v_amount NUMBER;
BEGIN
v_amount := v_qty * v_price;
DBMS_OUTPUT.PUT_LINE('amount = ' || v_amount);
END;
/DECLARE
*
ERROR at line 1:
ORA-01426: numeric overflow
ORA-06512: at line 6
Help: https://docs.oracle.com/error-help/db/ora-01426/SELECT 50000 * 60000 AS sql_number_result FROM dual;SQL_NUMBER_RESULT
-----------------
3000000000
1 row selected.SET SERVEROUTPUT ON
DECLARE
v_qty PLS_INTEGER := 50000;
v_price PLS_INTEGER := 60000;
v_amount NUMBER;
BEGIN
v_amount := CAST(v_qty AS NUMBER) * v_price;
DBMS_OUTPUT.PUT_LINE('amount = ' || v_amount);
END;
/amount = 3000000000
PL/SQL procedure successfully completed.03A SQL function result beyond the NUMBER range (EXP(500))
SELECT EXP(500) FROM dual fails with ORA-01426. NUMBER holds values below 1E126, and e to the 500th power is far larger. EXP(290) still fit and returned 8.819E+125.
Passing a BINARY_DOUBLE, EXP(CAST(500 AS BINARY_DOUBLE)), returned 1.404E+217. BINARY_DOUBLE has a much wider range, but it is a floating-point type and not exact like NUMBER.
SELECT EXP(500) AS growth FROM dual;SELECT EXP(500) AS growth FROM dual
*
ERROR at line 1:
ORA-01426: numeric overflow
Help: https://docs.oracle.com/error-help/db/ora-01426/SELECT EXP(290) AS exp_290 FROM dual; EXP_290
----------
8.819E+125
1 row selected.SELECT EXP(CAST(500 AS BINARY_DOUBLE)) AS growth FROM dual; GROWTH
----------
1.404E+217
1 row selected.FAQ
What is the maximum value of PLS_INTEGER?
2147483647 (POWER(2, 31) - 1). Any result above it, from addition or multiplication, raises ORA-01426.
Why do I get ORA-01426 when the result variable is NUMBER?
Because the calculation happens in the type of its operands. PLS_INTEGER * PLS_INTEGER is computed as PLS_INTEGER and overflows before it is assigned. Cast one operand to NUMBER, as in CAST(v_qty AS NUMBER) * v_price.
The same calculation works in SQL but fails in PL/SQL. Why?
SQL computes 50000 * 60000 as NUMBER, which returned 3000000000. In PL/SQL, two PLS_INTEGER variables are multiplied as PLS_INTEGER and overflow.
How do I find which line caused ORA-01426?
Look at ORA-06512: at line N under the error. On this page it pointed to line 5 (the addition in the loop) and line 6 (the multiplication).
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0