Solved

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

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

I have a sample Table
CREATE TABLE TEST (TEST_COL VARCHAR2(10) NULL)
INSERT INTO TEST VALUES ('TEST VALUE')
in both the Databases

Whenever I query
SELECT TO_CHAR(TEST_COL) TEST_COL FROM TEST

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 ..
Regds,
Karthick.
0
Comment
Question by:karthick79
[X]
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
10 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9910192
0
 
LVL 24

Expert Comment

by:shivsa
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
0
 
LVL 7

Expert Comment

by:jocave
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;
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:seazodiac
ID: 9911995
karthick79:

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
0
 
LVL 10

Accepted Solution

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

0
 
LVL 1

Author Comment

by:karthick79
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 ..

Regds,
Karthick.
0
 
LVL 15

Expert Comment

by:andrewst
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.
0
 
LVL 10

Expert Comment

by:SDutta
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 :
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions133a.htm#SQLRF06128

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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 how to recover a database from a user managed backup
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

628 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