Ora 06502 pl sql numeric or value error null index table key value

Are you getting an ORA-06502 error message when working with Oracle SQL? Learn how to resolve it and what causes it in this article.

Are you getting an ORA-06502 error message when working with Oracle SQL? Learn how to resolve it and what causes it in this article.

ORA-06502 Cause

The cause of the “ORA-06502 PL/SQL numeric or value error” can be one of many things:

  1. A value is being assigned to a numeric variable, but the value is larger than what the variable can handle.
  2. A non-numeric value is being assigned to a numeric variable.
  3. A value of NULL is being assigned to a variable which has a NOT NULL constraint.

Let’s take a look at the solutions for each of these causes.

The solution for this error will depend on the cause.

Let’s see an example of each of the three causes mentioned above.

Solution 1: Value Larger than Variable (Number Precision Too Large)

In this example, we have some code that is setting a numeric variable to a value which is larger than what can be stored.

Let’s create this procedure which declares and then sets a variable:

CREATE OR REPLACE PROCEDURE TestLargeNumber
AS
  testNumber NUMBER(3);
BEGIN
  testNumber := 4321;
END;

If we compile it, it compiles with no errors.

Procedure TESTLARGENUMBER compiled

Now, let’s run the procedure.

EXEC TestLargeNumber;

We get an error:

Error starting at line : 8 in command -
EXEC TestLargeNumber
Error report -
ORA-06502: PL/SQL: numeric or value error: number precision too large
ORA-06512: at "SYSTEM.TESTLARGENUMBER", line 5
ORA-06512: at line 1
06502. 00000 -  "PL/SQL: numeric or value error%s"
*Cause:    An arithmetic, numeric, string, conversion, or constraint error
           occurred. For example, this error occurs if an attempt is made to
           assign the value NULL to a variable declared NOT NULL, or if an
           attempt is made to assign an integer larger than 99 to a variable
           declared NUMBER(2).
*Action:   Change the data, how it is manipulated, or how it is declared so
           that values do not violate constraints.

The error we’ve gotten is “ORA-06502: PL/SQL: numeric or value error: number precision too large”. It also includes an ORA-06512, but that error just mentions the next line the code is run from, as explained in this article on ORA-06512.

This is because our variable testNumber can only hold 3 digits, because it was declared as a NUMBER(3). But, the value we’re setting it to a few lines later is 4 digit long (4321).

So, the value is too large for the variable.

To resolve it, increase the size of your variable, or manipulate your value to fit the size of the variable (if possible).

In our example , we can change the size of the variable.

CREATE OR REPLACE PROCEDURE TestLargeNumber
AS
  testNumber NUMBER(4);
BEGIN
  testNumber := 4321;
END;
Procedure TESTLARGENUMBER compiled

Now, let’s run the procedure.

EXEC TestLargeNumber;
PL/SQL procedure successfully completed.

The procedure runs successfully. We don’t get any output (because we didn’t code any in), but there are no errors.

Read more on the Oracle data types here.

Solution 2: Non-Numeric Value

Another way to find and resolve this error is by ensuring you’re not setting a numeric variable to a non-numeric value.

For example, take a look at this function.

CREATE OR REPLACE PROCEDURE TestNonNumeric
AS
  testNumber NUMBER(4);
BEGIN
  testNumber := 'Yes';
END;
Procedure TESTNONNUMERIC compiled

The procedure compiles successfully. Now, let’s fun the function.

EXEC TestNonNumeric;
Error starting at line : 8 in command -
EXEC TestNonNumeric
Error report -
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "SYSTEM.TESTNONNUMERIC", line 5
ORA-06512: at line 1
06502. 00000 -  "PL/SQL: numeric or value error%s"
*Cause:    An arithmetic, numeric, string, conversion, or constraint error
           occurred. For example, this error occurs if an attempt is made to
           assign the value NULL to a variable declared NOT NULL, or if an
           attempt is made to assign an integer larger than 99 to a variable
           declared NUMBER(2).
*Action:   Change the data, how it is manipulated, or how it is declared so
           that values do not violate constraints.

The error we get is “ORA-06502: PL/SQL: numeric or value error: character to number conversion error”.

This happens because our variable testNumber is set to a NUMBER, but a few lines later, we’re setting it to a string value which cannot be converted to a number

To resolve this error:

  1. Ensure the value coming in is a number and not a string.
  2. Convert your string to a number using TO_NUMBER (the conversion might happen implicitly but this may help).
  3. Convert your string to the ASCII code that represents the string using the ASCII function.
  4. Change the data type of your variable (but check that your code is getting the right value first).

The solution you use will depend on your requirements.

Solution 3: NOT NULL Variable

This error can appear if you try to set a NULL value to a NOT NULL variable.

Let’s take a look at this code here:

CREATE OR REPLACE PROCEDURE TestNonNull
AS
  testNumber NUMBER(4) NOT NULL := 10;
  nullValue NUMBER(4) := NULL;
BEGIN
  testNumber := nullValue;
END;

Procedure TESTNONNULL compiled

Now, the reason we’re using a variable to store NULL and not just setting testNumber to NULL is because we get a different error in that case. Besides, it’s probably more likely that your NULL value will come from another system or a database table, rather than a hard-coded NULL value.

Let’s run this function now.

Error starting at line : 9 in command -
EXEC TestNonNull
Error report -
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "SYSTEM.TESTNONNULL", line 6
ORA-06512: at line 1
06502. 00000 -  "PL/SQL: numeric or value error%s"
*Cause:    An arithmetic, numeric, string, conversion, or constraint error
           occurred. For example, this error occurs if an attempt is made to
           assign the value NULL to a variable declared NOT NULL, or if an
           attempt is made to assign an integer larger than 99 to a variable
           declared NUMBER(2).
*Action:   Change the data, how it is manipulated, or how it is declared so
           that values do not violate constraints.

We get the ORA-06502 error.

This error message doesn’t give us much more information. But, we can look at the code on line 6, as indicated by the message. We can see we have a variable that has a NOT NULL constraint, and the variable is NULL.

To be sure, we can output some text in our demo when it is null.

CREATE OR REPLACE PROCEDURE TestNonNull
AS
  testNumber NUMBER(4) NOT NULL := 10;
  nullValue NUMBER(4) := NULL;
BEGIN
  IF (nullValue IS NULL) THEN
    dbms_output.put_line('Value is null!');
  ELSE
    testNumber := nullValue;
  END IF;
END;

Now let’s call the procedure.

EXEC TestNonNull;
Value is null!

The output shows the text message, indicating the value is null.

ORA-06502 character string buffer too small

This version of the error can occur if you set a character variable to a value larger than what it can hold.

When you declare character variables (CHAR, VARCHAR2, for example), you need to specify the maximum size of the value. If a value is assigned to this variable which is larger than that size, then this error will occur.

For example:

DECLARE
  charValue VARCHAR2(5);
BEGIN
  charValue := 'ABCDEF';
END;

If I compile this code, I get an error:

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

This happens because the variable is 5 characters long, and I’m setting it to a value which is 6 characters long.

You could also get this error when using CHAR data types.

DECLARE
  charValue CHAR(5);
BEGIN
  charValue := 'A';
  charValue := charValue || 'B';
END;
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 5

This error happens because the CHAR data type uses the maximum number of characters. It has stored the value of A and added 4 space characters, up until its maximum value of 5.

When you try to concatenate a value of B to it, the resulting value is ‘A    B’, which is 6 characters.

To resolve this, use a VARCHAR2 variable instead of a CHAR, and ensure the maximum size is enough for you.

ORA-06502: pl/sql: numeric or value error: null index table key value

Sometimes you might get this error message with the ORA-06502 error:

ORA-06502: pl/sql: numeric or value error: null index table key value

This means that either:

  • Your index variable is not getting initialized, or
  • Your index variable is getting set to NULL somewhere in the code.

Check your code to see that neither of these two situations are happening.

ORA-06502: pl/sql: numeric or value error: bulk bind: truncated bind

You might also get this specific error message:

ORA-06502: pl/sql: numeric or value error: bulk bind: truncated bind

This is caused by an attempt to SELECT, UPDATE, or INSERT data into a table using a PL/SQL type where a column does not have the same scale as the column in the table.

For example, you may have declared a variable in PL/SQL to be VARCHAR2(100), but your table is only a VARCHAR2(50) field. You may get this error then.

You may also get this error because some data types in PL/SQL have different lengths in SQL.

To resolve this, declare your variables as the same type as the SQL table:

type t_yourcol is table of yourtable.yourcol%TYPE;

So, that’s how you resolve the ORA-06502 error.

Lastly, if you enjoy the information and career advice I’ve been providing, sign up to my newsletter below to stay up-to-date on my articles. You’ll also receive a fantastic bonus. Thanks!

Learn the cause and how to resolve the ORA-06502 error message in Oracle.

Description

When you encounter an ORA-06502 error, the following error message will appear:

  • ORA-06502: PL/SQL: numeric or value error

Cause

You tried to execute a statement that resulted in an arithmetic, numeric, string, conversion, or constraint error.

The common reasons for this error are:

  1. You tried to assign a value to a numeric variable, but the value is larger than the variable can handle.
  2. You tried to assign a non-numeric value to a numeric variable and caused a conversion error.

Resolution

Let’s look at three options on how to resolve the ORA-06502 error:

Option #1 — Value too large

In our first option, this error occurs when you try to assign a value to a numeric variable, but the value is larger than the variable can handle.

For example, if you created a procedure called TestProc as follows:

SQL> CREATE OR REPLACE PROCEDURE TestProc
  2  AS
  3    v_number number(2);
  4  BEGIN
  5    v_number := 100;
  6  END;
  7  /

Procedure created.

This procedure was successfully created. But when we try to execute this procedure, we will get an ORA-06502 error as follows:

SQL> execute TestProc();
BEGIN TestProc(); END;

*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: number precision too large
ORA-06512: at "EXAMPLE.TESTPROC", line 5
ORA-06512: at line 1

The first line of the error message (ie: ORA-06502) indicates the error that occurred, while the second line of the error message (ie: ORA-06512) indicates that the error occurred at line 5 of the PLSQL code.

In this example, you’ve tried to assign a 3 digit number to a variable called v_number that can only handle 2 digits. You could correct this error by redefining the v_number variable as number(3).

SQL> CREATE OR REPLACE PROCEDURE TestProc
  2  AS
  3    v_number number(3);
  4  BEGIN
  5    v_number := 100;
  6  END;
  7  /

Procedure created.

And now when we execute our TestProc procedure, the ORA-06502 error has been resolved.

SQL> execute TestProc();

PL/SQL procedure successfully completed.

Option #2 — Conversion error

In our second option, this error occurs if you are trying to assign a non-numeric value to a numeric variable.

For example, if you created a procedure called TestProc as follows:

SQL> CREATE OR REPLACE PROCEDURE TestProc
  2  AS
  3    v_number number(2);
  4  BEGIN
  5    v_number := 'a';
  6  END;
  7  /

Procedure created.

This procedure was successfully created. But when we try to execute this procedure, we will get an ORA-06502 error as follows:

SQL> execute TestProc();
BEGIN TestProc(); END;

*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "EXAMPLE.TESTPROC", line 5
ORA-06512: at line 1

In this example, the value of ‘a’ does not properly convert to a numeric value. You can correct this error by assigning the variable called v_number a proper numeric value.

SQL> CREATE OR REPLACE PROCEDURE TestProc
  2  AS
  3    v_number number(2);
  4  BEGIN
  5    v_number := ASCII('a');
  6  END;
  7  /

Procedure created.

And now when we execute our TestProc procedure, the ORA-06502 error has been resolved.

SQL> execute TestProc();

PL/SQL procedure successfully completed.

Option #3 — Assigning NULL to a NOT NULL constrained variable

In our third option, this error occurs if you are trying to assign a NULL value to a NOT NULL constrained variable.

For example, if you created a procedure called TestProc as follows:

SQL> CREATE OR REPLACE PROCEDURE TestProc
  2  AS   
  3    v_non_nullable_variable VARCHAR2(30) NOT NULL := '5';
  4    v_null_variable         VARCHAR2(30)          := NULL;
  5  BEGIN
  6    v_non_nullable_variable := v_null_variable;
  7  EXCEPTION
  8    WHEN OTHERS THEN
  9      dbms_output.put_line(SQLERRM);
  10 END;
  11 /

Procedure created.

This procedure was successfully created. But when we try to execute this procedure, we will get an ORA-06502 error as follows:

ORA-06502: PL/SQL: numeric or value error

In this example, you can not assign a NULL value to the variable called v_non_nullable_variable. You can correct this error removing NOT NULL from the variable declaration of the v_non_nullable_variable as follows:

SQL> CREATE OR REPLACE PROCEDURE TestProc
  2  AS   
  3    v_non_nullable_variable VARCHAR2(30) := '5';
  4    v_null_variable         VARCHAR2(30) := NULL;
  5  BEGIN
  6    v_non_nullable_variable := v_null_variable;
  7  EXCEPTION
  8    WHEN OTHERS THEN
  9      dbms_output.put_line(SQLERRM);
  10 END;
  11 /

Procedure created.

Visit the Below Website to access unlimited exam questions for all IT vendors and Get Oracle Certifications for FREE

http://www.free-online-exams.com

Problem:
On : 11.5.10.2 version, Reports Issues

When attempting to run report for Unapplied Receipts Journal ,
the following error occurs.

ERROR
————————
One or more post-processing actions failed. Consult the OPP service log for details.

Error executing cursor.
ORA-06502: PL/SQL: numeric or value error: NULL index table key value
ORA-06512: at «APPS.FA_RX_PUBLISH», line 2153.

Symptoms:
Go to AR receivable manager responsibility.
View menu request->single request and run the below reports.

1) Unapplied Receipts Journal
2) Unapplied and Unresolved Receipts Register

Log files:
See the following error: One or more post-processing actions failed. Consult the OPP service log for details.

Filename = FNDOPP94524.txt
See the following:
Caused by: oracle.xdo.parser.v2.XMLParseException: Start of root element expected.
at oracle.xdo.parser.v2.XMLError.flushErrors1(XMLError.java:324)
at oracle.xdo.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:319)
at oracle.xdo.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:281)
at oracle.xdo.parser.v2.XMLParser.parse(XMLParser.java:266)
… 17 more

Solution:

Issue may be caused due to insufficient memory and incorrect setups in XML Publisher
please follow the action plan in a test environment:
1.
Navigation Path : XML Publisher Administration responsibility
-> Tab : Administration
-> Configuration
-> Properties
-> General
-> Temporary Directory
.
Please specify a directory that has plenty of space.

-> Tab : Data Definition
-> Search for the data definition:
Name: Subledger Period Close Exceptions Report
Application: Subledger Accounting
-> View the data definition
-> On the View Data Definition page, click on the Edit Configuration button (similar
navigation path for Templates)
-> Properties
-> FO Processing
.
2.
Set the following:
Use XML Publisher’s XSLT processor = TRUE
Enable scalable feature of XSLT processor = TRUE

3.
Please change the Output for the ARXSGPO and ARXSGP concurrent programs to XML and save
(SysadminConcurrentProgramDefine). Both programs need to be set to XML

4.
Restart the Concurrent Managers

References:

Note 869522.1: Statement Generation Program ending in XDOException «java.lang.reflect.InvocationTargetException».

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Ora 06502 pl sql numeric or value error character string buffer too small
  • Oracle dbms error text
  • Oracle sql developer ошибка ввода вывода
  • Ora 06502 pl sql numeric or value error bulk bind truncated bind
  • Oracle db error log

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии