Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1205
  • Last Modified:

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

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 ..
1 Solution
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
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;
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  


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

karthick79Author Commented:
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 ..

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now