Question

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

Asked by: shaynegw

Hi

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.pamount) + to_number(c1_rec.paint)) makes no difference, but again this script works elsewhere so I am not sure why this one machine can't run it.

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('key: '||key_id||' pdate: '||pdate||' gross: '|| null||
      ' 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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-07-10 at 07:51:59ID20674454
Tags

error

,

numeric

,

value

,

number

,

conversion

Topic

Oracle 3rd Party Tools

Participating Experts
5
Points
125
Comments
10

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ORA-06530 and ORA-06512
    Hello, I have a WinNT 4.0 sp6a iis 4.0 web server using mts and Microsoft ODBC driver for oracle to call a stored procedure. Works fine when it is called once but if it is called multiple times in a row I get the following error: 6/12/01 11:56:26 AM GetDataByProcC: -214746...
  2. varchar2
    what is the history of varchar2.I mean why it is varchar2 rather varchar.
  3. DBMS_XMLDOM.NEWDOMDOCUMENT function call error …
    Hi, OS : Windows Server 2003 I installed Oracle Patchset 9.2.0.5 recently. I installed Oracle ODBC Driver 9.2.0.6.3 also. Previously, I had 9.2.0.2 version. On this previous version, a stored procedure which contained the function : DBMS_XMLDOM.NEWDOMDOCUMENT(ClobParameter)...
  4. dbms_xmldom.writeToFile() raises ORA-06502 w…
    Hi all, i am trying to create an XML-File from within PL/SQL but there is a big problem when filesize begins to grow. Using dbms_xmldom.writeToFile(doc, temp_filename) (Version with 2 parameters) the file is created without any problems (370kB) but when a 3rd parameter is s...
  5. PL/SQL ORA-06512
    Very simple proc, but can't execute it!!! Getting the dreaded ORA-06512 error: PL/SQL: numeric or value error: character string buffer too small PROC: CREATE OR REPLACE PROCEDURE jjblogp.pgetblogdescription( inBLOG_ID IN NUMBER, outBLOG_DESCN_TXT out varchar2 ) AS B...
  6. ORA-06502: PL/SQL: numeric or value error
    i have following test pl/sql script: DECLARE ded CLOB; total_sum clob; finalstr clob; BEGIN DBMS_OUTPUT.ENABLE(NULL); ded := 'CASE WHEN paid1 > ind THEN ind ELSE paid1 END'; FOR i IN 1..4 LOOP IF i = 1 THEN total_sum := 'CASE WHEN paid1 > ind THEN ind ELSE paid1 END...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

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;

 

by: yorenPosted on 2003-07-10 at 08:43:43ID: 8894013

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.

 

by: shaynegwPosted on 2003-07-10 at 09:13:39ID: 8894294

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

 

by: yorenPosted on 2003-07-10 at 09:24:22ID: 8894376

Are all your machines hitting the exact same database?

It only be a conversion problem. Maybe it's somewhere else. Are you sure you got the line number right?

 

by: m1lPosted on 2003-07-10 at 09:50:25ID: 8894610

I'd move your commented out DBMS_OUTPUT line  to just after the LOOP and uncomment it and then run it.  If it's not obvious from the output why it would fail, maybe post it here and we can all have a think about it  :-)

 

by: anand_2000vPosted on 2003-07-11 at 03:26:32ID: 8900904

It might also be a special character problem. Can you individually type the script again in the specific machine and then execute it again instead of copy paste?

 

by: Uncertified_DBAPosted on 2003-07-14 at 02:52:49ID: 8915704

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,

 

by: shaynegwPosted on 2003-07-14 at 08:50:02ID: 8918151

The problem was in the NLS settings. Thanks to all and thanks to m1| for the procedure to test field integrity.

Take care,
Shayne

 

by: boy3696Posted on 2003-08-28 at 13:00:17ID: 9243403

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...

 

by: shaynegwPosted on 2003-08-28 at 14:47:50ID: 9244011

Hi

All of our databases are setup with AMERICAN_AMERICA.WE8ISO8859P1 for NLS_DATABASE. So your solution will be based in your database NLS settings, which might be different than mine. We were having problems with a SQL*Plus Oracle client that had different NLS_SESSION
 
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\SOFTWARE\ORACLE\NLS_LANG to AMERICAN_AMERICA.WE8ISO8859P1

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.WE8ISO8859P1

I also found this document to be a handy resource: http://www.fors.com/orasupp/rdbms/nls/15389_1.HTM

Take care,
Shayne

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...