ora-06512 is one of the common errors in PLSQL.In this post, we will see how do I fix ora-06512 error
Description in Oracle database
ORA-06512 in Oracle is one of the common errors seen in PLSQL programs in the Oracle database
Here is what Oracle documentation says about this error
Reference: Oracle documentation on 6512
You can find this 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:
Let’s see a few examples of 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, the procedure get compiled successfully but it gives errors while the 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 an 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 row in the db_node table and get multiple values for each 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 the 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-06512 Error Message
Related articlesORA-00911
ORA-03113
ORA-00257
ORA-27154
ORA-29913
ORA-20001 in Gather schema stats on 11g(FND_HISTOGRAM_COLS)