Oracle To_Char: Error > Invalid Number .. Different Oracle Terminals

Posted on 2003-12-09
Last Modified: 2009-12-16
Hi Experts,
I have 2 Oracle Servers viz..
Hostname: OraLin .. Running on Linux. Version: Enterprise Edition
Hostname:Ora8 .. Running on Windows 2K Version: Enterprise Edition

I have a sample Table
in both the Databases

Whenever I query

The First Database throws an error ...
ORA-01722: invalid number
While the second database returns me the row ...
Any Answers ??
Thanks in Advance for ur time ..
Question by:karthick79
LVL 24

Expert Comment

ID: 9910192
LVL 24

Expert Comment

ID: 9910202
if u running this on linux and copying the test from windows, windows editor sometime may put extra character in the files. so please be aware when running on linux that u have to remove those characters.

How to fix it
The fix depends upon the exact expression which caused the problem. The following guide lists the possible SQL expressions which can give this error, with their most likely cause. When addressing this error, keep in mind that it can indicate a simple keystroke problem with the query, or a deeper problem with the query logic, or even the presence of bad data in the database itself.

You are doing an INSERT INTO ... VALUES (...)
One of the data items you are trying to insert is an invalid number. Locate and correct it.

If all of the numbers appear to be valid, then you probably have your columns out of order, and an item in the VALUES clause is being inserted into a NUMBER column instead of the expected VARCHAR2 column. This can happen when a table has columns added or removed

Expert Comment

ID: 9910218
I believe the problem is that to_char is unnecessary in this query.  Your column is already a string, there's no need to cast it to a string again.  In this case, the to_char function is, at best, a no op.

I don't have access to an 8.1.6 database, but I'd wager that on 8.1.6, there was no version of the to_char function that accepted a varchar2 parameter.  Thus, the 8.1.6 database has to convert the string input parameter to a number in order to call the to_char function that accepts a number.  Since this conversion isn't valid-- your data isn't a number-- you get an error.

You can simplify your life by just using the query

SELECT testCol
  FROM test;
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 23

Expert Comment

ID: 9911995

oracle TO_CHAR(column or expression, FORMAT) function requires the first parameter (column or expression) SHOULD be either NUMBER or DATE date type , and convert them to String. Therefore, you should Never use To_CHAR function againg VARCHAR2 OR CHAR data types.

Hope this helps
LVL 10

Accepted Solution

SDutta earned 250 total points
ID: 9914337
In Oracle 8.1.7 a change was made to fix bug 914145 which caused a change in the TO_CHAR functionality.

The change in behaviour in the TO_CHAR function from 8.1.7 onwards is that no numeric to string conversion is done if the parameter is of type char (i.e., NCHAR, NVARCHAR2, CLOB and NCLOB) and return as it is in the database
characterset format.

The above is not documented in the 8i documentation but is present in the 9i docs.


Author Comment

ID: 9918573
Thanx SDutta:
You seem to have taken me to the nearest problem resolution .. but I still need to get that problem solved in 8.1.6 Enterprise Edition ..
Any Answers ??
And Where Can i get a ECopy of Oracle 9i Docs, wherein they have mentioned about this bug ..

And anywayz .. u answer this or not .. the points are your for the taking mate ..

LVL 15

Expert Comment

ID: 9919958
> Any Answers ??

Presumably the resolution is not to apply the redundant TO_CHAR to a VARCHAR2 column?

Or upgrade to 8.1.7...

Just pointing this out - others gave you the answer already.
LVL 10

Expert Comment

ID: 9921658
Hi Karthick,

As everyone mentions the best solution for you is not to use the to_char function for NCHAR types in 8.1.6. What is the reason you want to do a TO_CHAR on the VARCHAR2 field ?

If the field may be either number or varchar2, even in 8.0 there will be an implicit conversion of datatype if you use a string function on a numeric date field, so you don't really need to do the to_char.

FYI the 9.2 documentation I mentioned that allows varchar parameters is here :


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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

860 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