Solved

Problem with To_Char string overflow (6502) error

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

CREATE OR REPLACE PROCEDURE test IS
    iunique         integer;
    vfour           varchar2(4);
    vfive           varchar2(5);
BEGIN
   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)
0
Comment
Question by:jrcooperjr
  • 3
  • 2
  • 2
7 Comments
 
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.
0
 
LVL 73

Accepted Solution

by:
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') ;
0
 
LVL 73

Expert Comment

by:sdstuber
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
0
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.

 
LVL 1

Author Closing Comment

by:jrcooperjr
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...
0
 
LVL 73

Expert Comment

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

Expert Comment

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

Just let us know if you agree.
0
 
LVL 1

Author Comment

by:jrcooperjr
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.
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PAYER_ID has both atributes 4 37
clob to char in oracle 3 38
oracle- set role and grant privileges 6 28
Help on model clause 5 31
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
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…

770 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