The problem is you have a record in PENCASH where PAMOUNT or PAINT has a character in it, so it can't be converted into a number.
Main Topics
Browse All TopicsHi
I have a situation where the attached script works fine with different SQL*Plus clients (8 and 9), on a variety of PCs (all W2K), with a variety of Oracle network databases (AIX and W2K: 7.3, 8.1.7, 9.0.2), but it will not work on one client machine.
The machine is a W2K PC running SQL*Plus 9.0.1.3.0 against an AIX Oracle 8.1.7 database. Once again, I can run the same script from another W2K machine, using the same SQL*Plus, against the same Oracle target, with the same Oracle login, so I am confident that the problem is related to a configuration issue on the machine where the script will not work.
The error I get on that machine is:
"ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at line 40"
The suspect lines seem to be:
...
subtotal := to_number(c1_rec.pamount) + to_number(c1_rec.paint);
insert into pencash_calc
values(key_id, pdate, null, c1_rec.pmemo, null, c1_rec.payto, subtotal);
...
subtotal is a varchar with numerical assignments, and subtotal := to_char(to_number(c1_rec.p
If we comment out the subtotal := line and replace the field insertion with a null, the script works on the suspect machine.
I have also compared the SQL*Plus environment options, and tnsnames.ora and sqlnet.ora files between the suspect machine and a working one, and but I could find no significant differences.
Any ideas on what to look for on the suspect machine or what the underlying problem is?
Thanks and take care,
Shayne
script:
/*
SQL> desc pencash
Name Null? Type
--------------------------
KEY VARCHAR2(14)
FDATE DATE
PDATE DATE
PAMOUNT VARCHAR2(40)
PAINT VARCHAR2(40)
PAYTO VARCHAR2(40)
PMEMO VARCHAR2(40)
PCHNO VARCHAR2(8)
*/
/*
SQL> desc pencash_calc;
Name Null? Type
--------------------------
KEY_ID VARCHAR2(40)
PDATE DATE
GROSSAMT VARCHAR2(40)
PMEMO VARCHAR2(50)
PER_CENT VARCHAR2(40)
PAYTO VARCHAR2(40)
SUBTOTAL VARCHAR2(80)
*/
truncate table pencash_calc;
DECLARE
CURSOR c1 IS
SELECT
p.key,
p.pdate,
p.pmemo,
p.payto,
p.pamount,
p.paint
FROM pencash p
-- group by p.key, p.date
ORDER BY p.key;
c1_rec c1%ROWTYPE;
w_sql_code number := 0;
w_sql_mssg varchar2(79);
gross_amt varchar2(40) := 0;
Key_id varchar2(10);
pdate date;
temp_Key varchar2(10);
temp_pdate date;
temp_pmemo varchar2(50);
temp_payto varchar2(9);
subtotal varchar2(80);
BEGIN
OPEN c1;
FETCH c1 into c1_rec;
temp_key := c1_rec.key;
temp_pdate := c1_rec.pdate;
LOOP
EXIT WHEN c1%NOTFOUND;
key_id := c1_rec.key;
pdate := c1_rec.pdate;
subtotal := to_number(c1_rec.pamount) + to_number(c1_rec.paint);
/*dbms_output.put_line('ke
' memo: '||c1_rec.pmemo||' percent: '||null||' payto: '||c1_rec.payto||
' subtotal: '||subtotal);*/
insert into pencash_calc
values(key_id, pdate, null, c1_rec.pmemo, null, c1_rec.payto, subtotal);
if pdate = temp_pdate and temp_key = key_id then
gross_amt := gross_amt + subtotal;
else
update pencash_calc
set grossamt = gross_amt
where key_id = temp_key
and pdate = temp_pdate;
temp_pdate := pdate;
temp_key := key_id;
gross_amt := gross_amt + subtotal;
end if;
FETCH c1 into c1_rec;
END LOOP;
CLOSE c1;
COMMIT;
END;
/
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks for the ideas so far
I checked and found that there are no characters in the PENCASH.PAMOUNT or PENCASH.PAINT fields. This makes sense to me because my script works on all machines but one. If there was an inadvertent character in either of those fields, I would expect the script to always fail.
Thanks and take care,
Shayne
Set the charcterset in the problematic W2K PC to the one in the database. The Clients settings takes precedence over the server settings
There are three level of settings
check from the client m/c
SELECT * FROM NLS_INSTANCE_PARAMETERS;
SELECT * FROM NLS_DATABASE_PARAMETERS;
SELECT * FROM NLS_SESSION_PARAMETERS;
set the client m/c and most probably your problem will be resolved
hope this helps
Regards,
Shaynegw or Uncertified_DBA...
I'm having this same issue/problem that's been driving me nuts these past couple of months, but I'm no where near a DB Administrator etc... to understand how to fix it based on the notes above...
Can someone email me or tell me how to do this? Please? I'm begging now! :)
Any help would be appreciated. I just don't know how to check my local machine, (ie: where to go to check this, or how to do it), and also the server as well... Our DBA's don't have a clue.
Cheers...
Hi
All of our databases are setup with AMERICAN_AMERICA.WE8ISO885
Temporary Solution:
ALTER SESSION SET NLS_LANGUAGE=AMERICAN;
ALTER SESSION SET NLS_TERRITORY=AMERICA;
Permanent Solution that we used: reinstall Oracle SQL*Plus client with proper NLS settings
Another Solution: Someone with access to your machine registry (ie client support) could set HKEY_LOCAL_MACHINE\SOFTWAR
You should also be able to define NLS_LANG in ORACLE.INI if you have one. I have not tried this.
Regardless of which approach you use, when you run SELECT USERENV ('LANGUAGE') FROM DUAL; from the client side, you should see AMERICAN_AMERICA.WE8ISO885
I also found this document to be a handy resource: http://www.fors.com/orasup
Take care,
Shayne
Business Accounts
Answer for Membership
by: m1lPosted on 2003-07-10 at 08:41:20ID: 8893990
Trimming
;
ltrim(rtrim(
the fields before you try to do a to_number may help.
Also the data in the field may just not be numeric, a character may have sneaked in.
A really quick and dirty way of finding the row with a problem would be
declare
cursor all_cur IS
select key, pamount, paint
from pencash;
--
l_num_check NUMBER;
begin
for all_rec in all_cur loop
dbms_output.put_line('key = ' || all_rec.key);
--
l_num_check := to_number(all_rec.pamount)
l_num_check := to_number(all_rec.paint);
end loop;
end;