Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

character to number conversion problem? 2

Status
Not open for further replies.

SashaBuilder3

Programmer
Jan 13, 2002
131
CA
Hi everybody,

I have a PL/SQL procedure which reads values from a text file. Each read value (either string or numeric) first comes into a temporary VARCHAR2 variable named tmpValue. Some numeric values in the file can be -99 (meaning missing) which in the database should be assigned NULL.

So I put a simple statement:

if tmpValue = -99 then
tmpValue := NULL;
end if;


The whole procedure compiles OK but when I'm trying to run it in SQL*Plus I'm getting a message:

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

I also tried to change the first line into this

if TO_NUMBER(tmpValue) = -99 then

but it didn't work either (same error message).

Can anyone help with a correct syntax?



Thanks,

Alexandre
 

How about this?

if tmpValue = '-99' then
Robbie

"The rule is, not to besiege walled cities if it can possibly be avoided" -- Art of War
 
The problem seems that tmpValue can contain something else that numbers, for example spaces.

If you are sure that it can only contain number or spaces, you may test:

if trim(tmpValue)=-99
--> there is an implicit type conversion.

Anyway,
if trim(tmpValue)='-99'
is safer.
 
Robbie, Fmorel,


Thank you! Putting apostrophes made it work. Definitely the strings can contain spaces so I used the Trim() function as well.


Alexandre
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top