Solved

ORA-01722: invalid number

Posted on 2010-11-18
5
1,806 Views
Last Modified: 2013-12-07
why am i getting this error?
select to_char('10/15/2010 11:07:20 AM', 'mm/dd/yyyy hh:mi:ss AM') from dual;

ORA-01722: invalid number
0
Comment
Question by:gram77
  • 3
  • 2
5 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 34164177
you need to use to_char with a date not a raw string.

select to_date('10/15/2010 11:07:20 AM', 'mm/dd/yyyy hh:mi:ss AM') from dual;

0
 
LVL 1

Expert Comment

by:Lacca
ID: 34165248
Because '10/15/2010 11:07:20 AM' already is a char.

Worging Examples:

convert chat to date
select to_date('10/15/2010 11:07:20 AM', 'mm/dd/yyyy hh:mi:ss AM') from dual;

convert date to char
select to_char(SYSDATE, 'mm/dd/yyyy hh:mi:ss AM') from dual;

0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 500 total points
ID: 34165300
>>Because '10/15/2010 11:07:20 AM' already is a char.

To further clarify:  Actually you can call to_char with a char.

"select to_char('10/15/2010 11:07:20 AM') from dual;" will run just fine.  The invalid number error comes from Oracle dates being stored internally as a number and the to_char call referenced is expecting an Oracle date, a number, as the first parameter.
0
 
LVL 1

Expert Comment

by:Lacca
ID: 34171556
>>"select to_char('10/15/2010 11:07:20 AM') from dual;"

But what is the purpose of doing this?

0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34172599
>>But what is the purpose of doing this?

There would be no purpose.  I was just stating that the error wasn't caused by "Because '10/15/2010 11:07:20 AM' already is a char".  It was caused because '10/15/2010 11:07:20 AM' was not a number.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to take different types of Oracle backups using RMAN.

685 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