Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Problem with To_Char string overflow (6502) error

Posted on 2011-09-02
Last Modified: 2012-05-12
I've condensed my problem into a very simple procedure.  Here is the procedure:

    iunique         integer;
    vfour           varchar2(4);
    vfive           varchar2(5);
   iunique := 1330    ;
   vfive := to_char(iunique,'0009') ;
   vfour:= to_char(iunique,'0009') ;
END test;

When I execute this procedure, I get a 6502 error on the line using the to_char function with vfour.  The to_char line with vfive gives no error.

As I interpret things, I am converting a four-digit integer value to characters.  This should give me a four-character result.  

Shouldn't the four-character result fit in a four-character field?  

Any explanations as to why I'm getting the 6502 error when I'm trying to put the result in a four-character field, but no error when I put the result in a five character field?

(We're using Oracle 11g by the way)
Question by:jrcooperjr
  • 3
  • 2
  • 2
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36475891
I believe Integers are signed but cannot verify that from the docs right now since I an on mobile.
LVL 74

Accepted Solution

sdstuber earned 500 total points
ID: 36475900
to_char is trying to put a space in front of your digits  use "fm"

 vfour:= to_char(iunique,'fm0009') ;
LVL 74

Expert Comment

ID: 36475904
and yes,  the space is so there is room to put "-" if the number was negative
and if it was negative, it would still fail because '-0009'  won't fit into 4 characters
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Author Closing Comment

ID: 36475950
Argghhh.. thanks for reminding me to remember the space for signs.... I'd also forgotten that FM in a mask suppresses things not just in date strings...
LVL 74

Expert Comment

ID: 36476120
a split is probably in order, slightwv did mention signs first
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36476172
I do tend to agree about a split.

Just let us know if you agree.

Author Comment

ID: 36476295
I disagree about the split.... the key for me was the mention of "FM" to suppress the space... just knowing that there was a space for the sign would not --- in and of itself --- resolved my problem.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question