Problem with To_Char string overflow (6502) error

Posted on 2011-09-02
Medium Priority
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
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
  • 3
  • 2
  • 2
LVL 77

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 2000 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.


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 77

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
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 syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Suggested Courses

771 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