Skip to content
Oracle Database

Oracle Error ORA-06512

at line (PL/SQL error stack)

Applies to: Oracle Database 19c, 21c, 23ai and 26ai (same wording)
Last technically reviewed 24 October 2026 on Oracle Database Error Messages reference (26ai, 21c and 19c); not run locally
The full message
ORA-06512: at "SHOP.ADD_ORDER_LINE", line 14
Other forms of this message
In an anonymous block (no unit name)
ORA-06512: at line 2
A full stack: the real error comes first
ORA-01403: no data found
ORA-06512: at "SHOP.GET_PRICE", line 6
ORA-06512: at "SHOP.ADD_ORDER_LINE", line 14
ORA-06512: at line 2
From a trigger (ORA-04088 names the trigger)
ORA-20001: Order 1001 is already dispatched
ORA-06512: at "SHOP.ORDERS_BIU", line 5
ORA-04088: error during execution of trigger 'SHOP.ORDERS_BIU'
Error code
ORA-06512
Product
Oracle Database
Versions
Oracle Database 19c, 21c, 23ai and 26ai (same wording)
Last reviewed
24 October 2026

What it means

ORA-06512 is not the error to fix: it is a line of the PL/SQL error stack that says which program unit and line an unhandled exception passed through. The real error is the one printed above it.

When an exception is not handled, PL/SQL passes it up from the block where it was raised to each caller in turn. Oracle adds one ORA-06512 line for each level, naming the code block (schema and unit, or nothing for an anonymous block) and the line number. Oracle's reference says it directly: the cause of the exception is found by examining the other errors in the stack.

Read the stack from the top. The first line is the actual error, for example ORA-01403 no data found, ORA-06502 or a user-defined ORA-20000 to ORA-20999 error. The first ORA-06512 line under it is where that error was raised; each following line is the caller that invoked it, and the last line is the outermost call, often at line 1 or at line 2 of the block your client ran.

So "ORA-06512 at line 14" on its own tells you only where to look. Fix the error at the top, at the line the first ORA-06512 names, or add a handler there if the condition is expected.

Common causes

  • Any runtime error inside a stored procedure, function, package, trigger or anonymous block that no exception handler caught; the error is printed above the ORA-06512 lines.
  • A RAISE_APPLICATION_ERROR call, which puts a user-defined ORA-20000 to ORA-20999 error at the top and ORA-06512 lines under it.
  • An error in a trigger: the stack then also ends with ORA-04088 naming the trigger that failed, and the triggering statement is rolled back.
  • An exception handler that raises again, or raises another error: the stack can then show an error more than once, once for each place it was raised.
  • An error inside an Oracle-supplied package (owned by SYS) that your code called; its ORA-06512 lines point inside that package, and the line to change is the first one in your own code below them.

Diagnose it

Read-only These queries only read the data dictionary (USER_, ALL_ and DBA_ views) and dynamic performance views (V$). They do not change data, privileges or settings, so they are safe to run first. DBA_ and V$ views need the matching privileges.

Read the line each ORA-06512 names

Take the schema, unit and line from the first ORA-06512 line and read the source around it. Repeat for the next line if you need to see how the caller got there.

SELECT name, type, line, text
FROM all_source
WHERE owner = 'SHOP'
  AND name = 'GET_PRICE'
  AND line BETWEEN 3 AND 9
ORDER BY type, line;
What to look for

The statement that raised the error. For a package, the executable code is in the PACKAGE BODY rows, so read those first.

Which kind of unit is it?

SELECT object_name, object_type, status, last_ddl_time
FROM all_objects
WHERE owner = 'SHOP'
  AND object_name IN ('GET_PRICE', 'ADD_ORDER_LINE', 'ORDERS_BIU');
What to look for

Whether each name is a procedure, function, package or trigger, and whether it is valid. A recent last_ddl_time means the code changed recently, a good first suspect.

When the stack ends in ORA-04088: which triggers fire?

SELECT trigger_name, trigger_type, triggering_event, status
FROM all_triggers
WHERE table_owner = 'SHOP'
  AND table_name = 'ORDERS'
ORDER BY trigger_name;
What to look for

Every trigger on the table, with its timing and events. The one named in ORA-04088 raised the error at the top of the stack.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Fix the first error in the stack, not ORA-06512

Read-only

Open the page for the error at the top of the stack and work through its causes at the line the first ORA-06512 names. Once that error no longer happens, every ORA-06512 line under it disappears too.

Log the full stack and backtrace, then re-raise

Changes schema

Many applications show only the last line of the stack. In the top-level handler, record DBMS_UTILITY.FORMAT_ERROR_STACK (the errors) and DBMS_UTILITY.FORMAT_ERROR_BACKTRACE, which Oracle documents as showing the call stack at the point where the exception was raised, and then raise again so the caller still sees the failure.

CREATE OR REPLACE PROCEDURE shop.place_order (p_order_id IN NUMBER)
IS
BEGIN
  shop.add_order_line(p_order_id);
EXCEPTION
  WHEN OTHERS THEN
    shop.app_log.error(           -- your own logging procedure
      DBMS_UTILITY.FORMAT_ERROR_STACK || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
    RAISE;
END;
/

Handle the condition where it has a sensible answer

Changes schema

If the error at the top is an expected case, for example no row found for an optional lookup, handle that specific exception at the line where it happens and return a defined result. Leave other errors unhandled.

CREATE OR REPLACE FUNCTION shop.get_price (p_product_id IN NUMBER)
  RETURN NUMBER
IS
  v_price shop.products.price%TYPE;
BEGIN
  SELECT price INTO v_price FROM shop.products WHERE id = p_product_id;
  RETURN v_price;
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    RETURN NULL;   -- the caller treats NULL as unknown product
END;
/

Do not silence the stack with WHEN OTHERS THEN NULL

Read-only

A handler that catches everything and does nothing makes ORA-06512 go away, and the real error with it: the work silently does not happen. Oracle recommends an OTHERS handler at the top level of a program, but one that records the error and raises it again, as in the fix above.

Examples

A no-data error passed up through two procedures

Not reproduced here: no Oracle Database is installed for this site. The stack layout follows the examples in Oracle's PL/SQL Packages and Types Reference (DBMS_UTILITY) and PL/SQL Language Reference; the unit names and line numbers are illustrative. Read it top down: the error, where it was raised, then each caller.

CREATE OR REPLACE FUNCTION get_price (p_product_id IN NUMBER)
  RETURN NUMBER
IS
  v_price NUMBER;
BEGIN
  SELECT price INTO v_price FROM products WHERE id = p_product_id;   -- line 6
  RETURN v_price;
END;
/

BEGIN
  add_order_line(1001);   -- add_order_line calls get_price(999) at its line 14
END;
/
Expected result (documented format, not run)
ORA-01403: no data found
ORA-06512: at "SHOP.GET_PRICE", line 6
ORA-06512: at "SHOP.ADD_ORDER_LINE", line 14
ORA-06512: at line 2

An error from a trigger

Not reproduced here: no Oracle Database is installed for this site. The layout (error, ORA-06512 inside the trigger, then ORA-04088) follows the trigger example in Oracle's PL/SQL Language Reference; the line number is illustrative. Because the trigger raised the error itself, ORA-20001 is at the top of the stack and the UPDATE is rolled back.

CREATE OR REPLACE TRIGGER orders_biu
BEFORE UPDATE ON orders
FOR EACH ROW
BEGIN
  IF :OLD.status = 'DISPATCHED' THEN
    RAISE_APPLICATION_ERROR(-20001, 'Order ' || :OLD.id || ' is already dispatched');
  END IF;
END;
/

UPDATE orders SET status = 'CANCELLED' WHERE id = 1001;
Expected result (documented format, not run)
ORA-20001: Order 1001 is already dispatched
ORA-06512: at "SHOP.ORDERS_BIU", line 3
ORA-04088: error during execution of trigger 'SHOP.ORDERS_BIU'

An exception handler that fails again

Not reproduced here: no Oracle Database is installed for this site. This is the documented example from Oracle's PL/SQL Language Reference (exception propagation), with the schema shown as SHOP. The error appears twice because it was raised once in the body and again in the handler, at line 7.

CREATE OR REPLACE PROCEDURE print_reciprocal (n NUMBER) IS
BEGIN
  DBMS_OUTPUT.PUT_LINE(1/n);
EXCEPTION
  WHEN ZERO_DIVIDE THEN
    DBMS_OUTPUT.PUT_LINE('Error:');
    DBMS_OUTPUT.PUT_LINE(1/n || ' is undefined');   -- raises again
END;
/

BEGIN
  print_reciprocal(0);
END;
/
Expected result (documented format, not run)
ORA-01476: divisor is equal to zero
ORA-06512: at "SHOP.PRINT_RECIPROCAL", line 7
ORA-01476: divisor is equal to zero
ORA-06512: at line 2

How to prevent it

Make sure your application logs the whole error stack, not just its last line, and record DBMS_UTILITY.FORMAT_ERROR_BACKTRACE in top-level handlers. Name your units and keep them short so a unit and line number lead straight to one statement.

Handle only the exceptions you have a real answer for, as close as possible to where they happen, and let the rest propagate with their full stack.

Common questions

How do I fix ORA-06512?

You fix the error printed above it. ORA-06512 only says where that error passed through: the first ORA-06512 line is where it was raised, so read that unit and line and work on the error at the top of the stack.

Why are there several ORA-06512 lines?

One is added for each level the exception passed through on its way out: the unit where it was raised, then each caller, then the block your client ran. The order goes from the innermost call to the outermost.

What does "ORA-06512: at line 1" mean with no name?

The line belongs to an anonymous block, the BEGIN ... END your tool or application sent, which has no stored name. It is usually the last line of the stack; the lines above it name the stored code where the error really happened.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 24 October 2026; examples and diagnostics run on Oracle Database Error Messages reference (26ai, 21c and 19c); not run locally. Messages and explanations follow Oracle's Database Error Messages reference; no Oracle Database was available, so the examples were not run locally.

Still stuck on an Oracle error?

Browse the full Oracle error library, or get hands-on help from an experienced SQL professional.