• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Techgoeasy

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle
    • Oracle database
    • Oracle Ebusiness Suite
    • Oracle weblogic
    • Oracle Performance Tuning
    • Oracle Hyperion
    • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
  • General
Home » Oracle » Oracle Database » How to resolve ORA-06512 at line num

How to resolve ORA-06512 at line num

June 10, 2018 by techgoeasy Leave a Comment

Table of Contents

  • Description in Oracle database
  • Explanation of the ORA-06512 error:
  • Reasons for ORA-06512 error:
  • Examples of ORA-06512:

Description in Oracle database

ORA-06512  in oracle is one of the common error seen in PLSQL programs in Oracle database

Here is what Oracle documentation says about this error

ORA-06512Reference :Oracle documentation

You can find this always by typing below in Unix

oerr ORA 06512

Explanation of the ORA-06512 error:

Error ORA-06512 means the backtrace message as the stack is being unwound by unhandled exceptions in your PLSQL code. This is a catch-all error for All PLSQL exceptions and is commonly seen.

ORA 6512 does not indicate the actual error, but the line number of the unhandled error in the PLSQL code. ORA-6512 will typically appear in a message stack in which the preceding message names the reason for the error, such as in the following example:

ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 1112

In the above , the yellow highlighted error is the main error

Reasons for ORA-06512 error:

The options to resolve this Oracle error are:

1) Fix the condition that is causing the unhandled error.
2) Write an exception handler for this unhandled error.
3) Contact your Oracle DBA for help.

Examples of ORA-06512:

Lets see few example on how to work on it

CREATE OR REPLACE PROCEDURE Testora_proc
AS
Site_name varchar2(5);
begin
site_name := 'techgoeasy.com';
end;
/
Procedure created.
sql> Exec Testora_proc
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 5

In the example given above, procedure get compiled successfully but it gave errors while execution

So actual error is the error

ORA-06502: PL/SQL: numeric or value error: character string buffer too small

We can easily correct it by increasing the size of the variable

CREATE OR REPLACE PROCEDURE Testora_proc
AS
Site_name varchar2(20);
begin
site_name := 'techgoeasy.com';
end;
/
Procedure created.
SQL> Exec Testoraproc
PL/SQL procedure successfully completed.

We can solve this using exception handler also

CREATE OR REPLACE PROCEDURE Testora_proc
AS
Site_name varchar2(5);
begin
site_name := 'techgoeasy.com';
EXCEPTION
WHEN OTHERS THEN
site_name := 'tech';
end;
/
Procedure created.SQL>Exec Testoraproc;
PL/SQL procedure successfully completed.

Another example would be

CREATE OR REPLACE PROCEDURE Testora_proc
AS
node_name varchar2(5);
begin
select node into node_name from db_node;
end;
/
Procedure created
SQL> Exec Testora_proc;
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at “NODE_NAME”, line 4
ORA-06512: at line 1

Here ORA-01422 is the real error. we have more than 1 rows in db_node table and get multiple values for node.So one fix could be restricting one row

CREATE OR REPLACE PROCEDURE Testora_proc
AS
node_name varchar2(5);
begin
select node into node_name from db_node where rownum <2;
end;
/
Procedure created
SQL> Exec Testora_proc;
PL/SQL procedure successfully completed.

Another example would be

CREATE OR REPLACE PROCEDURE Testora_proc
AS
node_name varchar2(5);
begin
select node into node_name from db_node;
end;
/
Procedure created
SQL> Exec Testora_proc;
ORA-01403: no data found
ORA-06512: at “NODE_NAME”, line 4
ORA-06512: at line 1

Here ORA-01403 is the real error. we have no rows in db_node oracle table and we are getting no data found error.So one fix could be putting exception handling

CREATE OR REPLACE PROCEDURE Testora_proc
AS
node_name varchar2(5);
begin
select node into node_name from db_node where rownum <2;
EXCEPTION WHEN NO_DATA_FOUND  
THEN 
node_name := 'tech'; 
end; 
/
Procedure created
SQL> Exec Testora_proc;
PL/SQL procedure successfully completed.

Some more examples can be on SYS.UTL_FILE

SQL> declare
F_LOG  utl_file.file_type;
begin
F_LOG := utl_file.fopen('TESTDIR','k', 'w');
end;
/  2    3    4    5    6
declare
*
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 4

Here the main error is ORA-29283.  Check the solution by clicking the link

Hope you like this post on ORA-6512 Error Message

Related articles
ORA-00911
ORA-03113
ORA-00257
ORA-27154
ORA-29913
ORA-20001 in Gather schema stats on 11g(FND_HISTOGRAM_COLS)

Filed Under: Oracle, Oracle Database, Oracle Sql Tagged With: ORA-06512

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • How to use sed to remove comments and blank lines
  • How to recover database using RMAN
  • How to check Stale statistics
  • Java web start(JWS) in R12
  • How to delete the archive logs in Oracle

Copyright © 2023 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us