Oracle 23.26PL/SQLLab-verified · 2026-11-29

ORA-06512: at line

ORA-06512 only shows where the real error happened; the cause is the first ORA- line above it.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-06512: at "LAB_A.PRINT_CUSTOMER", line 4

Jump to a cause

  1. 01Variable too small inside a procedure (ORA-06502)
  2. 02Error deep in nested calls — the stack has several lines
  3. 03Anonymous block: line N counts from DECLARE

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-29 · container image gvenzl/oracle-free:23-slim

ORA-06512 never comes alone. It is the backtrace of a PL/SQL error: the first line is the real error, and each ORA-06512: at "OWNER.NAME", line N line shows one step of the call stack, deepest call first. The last ORA-06512: at line 1 is just the BEGIN ... END; that SQL*Plus wraps around EXEC.

In the three runs below, the first line was ORA-06502 or ORA-01403. Each case was fixed where that first error pointed, not by touching ORA-06512.

01Variable too small inside a procedure (ORA-06502)

print_customer declares v_name VARCHAR2(10) and selects a 19-character name into it. EXEC print_customer(1) failed with ORA-06502: character string buffer too small, then ORA-06512: at "LAB_A.PRINT_CUSTOMER", line 4.

Line 4 in user_source is the SELECT name INTO v_name statement. Changing the declaration to v_name customers.name%TYPE made the same EXEC print Samsung Electronics.

Setup
Setuprun as lab_a
CREATE TABLE customers (customer_id NUMBER PRIMARY KEY, name VARCHAR2(50));
INSERT INTO customers VALUES (1, 'Samsung Electronics');
COMMIT;
CREATE OR REPLACE PROCEDURE print_customer(p_id NUMBER) AS
  v_name VARCHAR2(10);
BEGIN
  SELECT name INTO v_name FROM customers WHERE customer_id = p_id;
  DBMS_OUTPUT.PUT_LINE(v_name);
END;
/
OUTPUT
Table created.


1 row created.


Commit complete.


Procedure created.
Reproducerun as lab_a
EXEC print_customer(1)
✕ ERROR
BEGIN print_customer(1); END;

*
ERROR at line 1:
ORA-06502: PL/SQL: value or conversion error: character string buffer too small
ORA-06512: at "LAB_A.PRINT_CUSTOMER", line 4
ORA-06512: at line 1
Help: https://docs.oracle.com/error-help/db/ora-06502/
Checkrun as lab_a
SELECT line, text FROM user_source WHERE name = 'PRINT_CUSTOMER' AND line IN (2, 4) ORDER BY line;
OUTPUT
      LINE
----------
TEXT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         2
  v_name VARCHAR2(10);

         4
  SELECT name INTO v_name FROM customers WHERE customer_id = p_id;


2 rows selected.
Fixrun as lab_a
CREATE OR REPLACE PROCEDURE print_customer(p_id NUMBER) AS
  v_name customers.name%TYPE;
BEGIN
  SELECT name INTO v_name FROM customers WHERE customer_id = p_id;
  DBMS_OUTPUT.PUT_LINE(v_name);
END;
/
OUTPUT
Procedure created.

Declaring variables with %TYPE keeps them the same size as the column.

After the fixrun as lab_a
SET SERVEROUTPUT ON
EXEC print_customer(1)
✓ SUCCESS
Samsung Electronics

PL/SQL procedure successfully completed.

02Error deep in nested calls — the stack has several lines

close_day calls calc_order, which calls the function get_price. The first call (item 10) printed total=1000, then item 20 failed. The stack was ORA-01403: no data found, then ORA-06512 at GET_PRICE line 4, CALC_ORDER line 4, CLOSE_DAY line 4, and line 1.

The top ORA-06512 (GET_PRICE) is where the error happened; the lines below are the callers. prices had no row for item 20. After inserting it, close_day printed total=1000 and total=300.

Setup
Setuprun as lab_a
CREATE TABLE prices (item_id NUMBER PRIMARY KEY, price NUMBER);
INSERT INTO prices VALUES (10, 500);
COMMIT;
CREATE OR REPLACE FUNCTION get_price(p_item NUMBER) RETURN NUMBER AS
  v_price NUMBER;
BEGIN
  SELECT price INTO v_price FROM prices WHERE item_id = p_item;
  RETURN v_price;
END;
/
CREATE OR REPLACE PROCEDURE calc_order(p_item NUMBER, p_qty NUMBER) AS
  v_total NUMBER;
BEGIN
  v_total := get_price(p_item) * p_qty;
  DBMS_OUTPUT.PUT_LINE('total=' || v_total);
END;
/
CREATE OR REPLACE PROCEDURE close_day AS
BEGIN
  calc_order(10, 2);
  calc_order(20, 1);
END;
/
OUTPUT
Table created.


1 row created.


Commit complete.


Function created.


Procedure created.


Procedure created.
Reproducerun as lab_a
EXEC close_day
✕ ERROR
total=1000
BEGIN close_day; END;

*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "LAB_A.GET_PRICE", line 4
ORA-06512: at "LAB_A.CALC_ORDER", line 4
ORA-06512: at "LAB_A.CLOSE_DAY", line 4
ORA-06512: at line 1
Help: https://docs.oracle.com/error-help/db/ora-01403/
Checkrun as lab_a
SELECT item_id, price FROM prices WHERE item_id IN (10, 20);
OUTPUT
   ITEM_ID      PRICE
---------- ----------
        10        500

1 row selected.
Fixrun as lab_a
INSERT INTO prices VALUES (20, 300);
COMMIT;
OUTPUT
1 row created.


Commit complete.
After the fixrun as lab_a
SET SERVEROUTPUT ON
EXEC close_day
✓ SUCCESS
total=1000
total=300

PL/SQL procedure successfully completed.

03Anonymous block: line N counts from DECLARE

In an anonymous block there is no object name, so the stack shows only ORA-06512: at line 4. Line 1 is DECLARE, so line 4 is v_qty := TO_NUMBER('12a');, which raised ORA-06502: character to number conversion error.

VALIDATE_CONVERSION('12a' AS NUMBER) returned 0 and '12' returned 1. Using TO_NUMBER('12a' DEFAULT NULL ON CONVERSION ERROR) let the block finish and print qty=NULL.

Reproducerun as lab_a
DECLARE
  v_qty NUMBER;
BEGIN
  v_qty := TO_NUMBER('12a');
END;
/
✕ ERROR
DECLARE
*
ERROR at line 1:
ORA-06502: PL/SQL: value or conversion error: character to number conversion error
ORA-06512: at line 4
Help: https://docs.oracle.com/error-help/db/ora-06502/
Checkrun as lab_a
SELECT VALIDATE_CONVERSION('12a' AS NUMBER) AS ok_12a, VALIDATE_CONVERSION('12' AS NUMBER) AS ok_12 FROM dual;
OUTPUT
    OK_12A      OK_12
---------- ----------
         0          1

1 row selected.
After the fixrun as lab_a
SET SERVEROUTPUT ON
DECLARE
  v_qty NUMBER;
BEGIN
  v_qty := TO_NUMBER('12a' DEFAULT NULL ON CONVERSION ERROR);
  DBMS_OUTPUT.PUT_LINE('qty=' || NVL(TO_CHAR(v_qty), 'NULL'));
END;
/
✓ SUCCESS
qty=NULL

PL/SQL procedure successfully completed.

FAQ

What does ORA-06512 at line mean?

It shows the location of the error, not the error itself. Look at the first ORA- line of the stack for the cause, and at the ORA-06512 lines for the object and line number.

Which ORA-06512 line should I look at first?

The first one under the real error. In the nested case it was GET_PRICE, line 4; the following lines were the procedures that called it.

How do I find the line number in the source?

Query user_source with the object name and line, for example SELECT line, text FROM user_source WHERE name = 'PRINT_CUSTOMER' AND line = 4.

Why is the last line always ORA-06512: at line 1?

SQL*Plus turns EXEC proc into BEGIN proc; END;. Line 1 of that block is the call itself.

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