3
declare
   l_tot number := 0;

begin
   for i in 1..apex_application.g_f08.count loop
      l_tot := l_tot + nvl(to_number(apex_application.g_f08(i)),0);
   end loop;

 if l_tot = nvl(to_number(:P21_TOTAL_PRICE),0) then
      return true;
   else
      return false;
   end if;
end;

Got below error with above code

ORA-06502: PL/SQL: numeric or value error: character to number conversion error

Error occurred with :P21_TOTAL_PRICE. What is the wrong ? How can i correct this ?

Ollie
  • 17,058
  • 7
  • 48
  • 59
Bishan
  • 15,211
  • 52
  • 164
  • 258

2 Answers2

4

Rather than using REPLACE you should use the more powerful REGEXP_REPLACE function. http://www.orafaq.com/wiki/REGEXP_REPLACE

You can then remove any non-numeric character from the string before then using the TO_NUMBER function.

In your case it would be something like:

REGEXP_REPLACE(:P21_TOTAL_PRICE, '[^0-9]+', ''); 

See my answer to almost the exact same question here: Oracle To_Char function How to handle if it's already a string

Community
  • 1
  • 1
Ollie
  • 17,058
  • 7
  • 48
  • 59
2

The error rises because the number that you're representing is actually a character string involving commas etc. When you put a to_number to that, Oracle cannot replace the commas.

You might want to use replace function to strip off the commas

Change

if l_tot = nvl(to_number(:P21_TOTAL_PRICE),0) then

to

if l_tot = nvl(to_number(replace(:P21_TOTAL_PRICE,',','')),0) then  
Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134