0

I have a problem with a pl/sql anonymous block. Although I can show the variables that get with select query, I get a casting error if I use it in update sentence.

My code looks like this:

set serveroutput on

DECLARE

var1 scheme.table.column1%type; /* number[8,0] */
var2 scheme.table.column2%type; /* number[8,2] */

BEGIN

/* return simple value */
select t.column1, t.column2
into var1, var2
from scheme.table t
where <condition>

DBMS_OUTPUT.PUT_LINE('Var1 is: ' || var1 || ' Var2 is:' || var2); /* fine!!*/

update scheme.table
set scheme.table.column1 = var1 + 1
where scheme.table.column2 = var2; /* that is line error*/

END;

/*
ORA-06502: PL/SQL: error : error de conversión de carácter a número numérico o de valor
ORA-06512: en línea 58
06502. 00000 -  "PL/SQL: numeric or value error%s"
*/

Can somenone help me?

1
  • what is the value of var1 and var2 that gives you an error? Commented May 16, 2012 at 11:17

3 Answers 3

1

Could it be that var1+1 results in a number larger than number[8,0] for a record where column2=val2?

You query using "condition" but update using "column2=var2". So potentially you update many more rows than you may think you do.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Rene. I finally solved it. Code is correct, but no sqldeveloper. I compile same code sucessfully, so i was looking in wrong place.
0

ORA-06502: PL/SQL: numeric or value error string 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.

i think you error is the second choice.

reference to you error ORA-06502

2 Comments

@user1398399 please provide the create table script especially its constraints
Thank you shareef. I finally solved it. Code is correct, but no sqldeveloper. I compile same code sucessfully, so i was looking in wrong place.
0

Code is correct, problem with compiler, sqldeveloper.

1 Comment

WHAT was the problem please specify ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.