Меню Закрыть

Ora 06502 pl sql

Содержание

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:

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

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).

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

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:

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

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.

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

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:

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

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:

Я начал получать сообщение об ошибке ниже, так как я добавил o_ID к процедуре, все работало нормально, пока я не добавил в o_ID это связано с o_ID быть установленным как неправильный тип данных возможно? Я просмотрел любые другие связанные темы на SO, но безрезультатно.

o_ID изначально устанавливается, как показано ниже PR_LOAD_XML_FILE называется:

Из журналов

Процедура Spec

Тело процедуры

Решение

Я думаю, что когда вы вызываете свою процедуру, вы устанавливаете переменную для получения значения o_ID в виде строки. Вот мой пакет, который издевается над твоим:

В SQL * Plus я сначала определю эти две переменные связывания. Обратите внимание, что для переменной bind v_o_ID установлено значение varchar2 (4). Это предназначено для потерпеть поражение потому что значение o_ID установлено в 999999 в процедуре, которая длиннее 4 символов (если значение o_ID было установлено равным 9999, что составляет 4 символа или менее, то вызов процедуры работал бы нормально, но ошибка все равно будет присутствовать, и будет появляться Вы, как только значение o_ID станет больше 4 символов):

Читайте также:  Как исправить масштаб на компьютере

Теперь я вызываю процедуру в SQL * Plus, и она будет потерпеть поражение:

Теперь я установлю переменную связывания v_o_ID в число, и вызов процедуры будет успех. Вы можете увидеть полученные значения из процедуры, если вы печатаете переменные связывания, используя print команда:

I tried the following code different ways, like by taking out the while or the if, but when I put both together (if and while), I always get the error at the end.

FIXED by changing how I declared the variable "a" to:

*Notice that here, the significant change is to use VARCHAR2 instead of CHAR (not the bigger length). According to @user272735 ‘s answer, that’s the key.

Рекомендуем к прочтению

Добавить комментарий

Ваш адрес email не будет опубликован.