ORA-06502 error for casting string to number (PL/SQL)

Multi tool use


ORA-06502 error for casting string to number (PL/SQL)
I have variable:
suma NUMBER(7,2) := 0;
I want to execute the following process:
suma := suma+cast(substr(jmbg,i,1) as number)*7;
But when I run this process it shows the following error message:
ORA-06502: PL/SQL: numeric or value error: character to number
conversion error.
It has problem with this line, so I have tried run this process with TO_NUMBER functions, but it did the same.
How can I convert the substring to number without error message?
From the substr, it looks like you're only trying to add a single digit? Does that substr definitely always extract number digits?
– Rup
46 mins ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You have to know the format in which the string represents the number; for example, does the string contain leading or trailing zeros? how many decimal digits, what is the decimal separator?, ... Once you know these things, we can find the appropriate format mask to use the to_number
– Aleksej
56 mins ago