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

x
?
Solved

How do I get around this problem "a non-numeric character was found where a numeric was expected "

Posted on 2011-02-21
10
Medium Priority
?
1,093 Views
Last Modified: 2012-05-11
When I run my code in PHP I get this error message: a non-numeric character was found where a numeric was expected. When I change the last line of code "to_date('1 ' || T1.months) desc " to "to_char('1 ' || T1.months) desc " it works fine. However, it does not sort the data. I am trying to get it to print the months starting with the most recent e.g (February 2011, January 2011, December 2010, ...).  Is there a work around this? Or should I try to do it in PHP using a recordset? Please help either way.

Thanks!
select T1.months, T2.totalehrs, T2.totaleexp as totaleexp,
       T2.totalahrs, T2.totalaexp, decode(T2.totalehrs,NULL,'No data Found','') as note
from (
      select to_char(add_months(sysdate,  0  ) , 'MONTH YYYY') as months from dual 
union select to_char(add_months(sysdate,  -1 ) , 'MONTH YYYY') as months from dual 
union select to_char(add_months(sysdate,  -2 ) , 'MONTH YYYY') as months from dual 
union select to_char(add_months(sysdate,  -3 ) , 'MONTH YYYY') as months from dual 
union select to_char(add_months(sysdate,  -4 ) , 'MONTH YYYY') as months from dual 
union select to_char(add_months(sysdate,  -5 ) , 'MONTH YYYY') as months from dual 
union select to_char(add_months(sysdate,  -6 ) , 'MONTH YYYY') as months from dual)  T1,
(
select to_char(completed,'MONTH YYYY') as months, 
    nvl2( SUM(EST_HRS), SUM(EST_HRS) , '0') as totalehrs, 
    nvl2( SUM(EST_EXP), SUM(EST_EXP) , '0') as totaleexp, 
    nvl2( SUM(ACTUAL_HRS), SUM(ACTUAL_HRS), '0') as totalahrs, 
    nvl2( SUM(ACTUAL_EXP), SUM(ACTUAL_EXP), '0') as totalaexp 
from Table 
where 
    completed >= add_months(sysdate,-6)
    group by to_char(completed,'MONTH YYYY')
)  T2
   where T1.months = T2.months(+)
   order by to_date('1 ' || T1.months) desc ;

Open in new window

0
Comment
Question by:taviaf
10 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
ID: 34943692
nvl2( SUM(EST_HRS), SUM(EST_HRS) , '0') as totalehrs,

is a problem, the '0' would be varchar, while the part before is numerical.

this would be ok:
nvl2( SUM(EST_HRS), SUM(EST_HRS) , 0) as totalehrs,


same for the lines below that.
0
 

Author Comment

by:taviaf
ID: 34944041
@ angellll, I made the change as you mentioned and I also removed the note column "decode(T2.totalehrs,NULL,'No data Found','') as note" and I still get the same error message: Warning: ociexecute() [function.ociexecute]: ORA-01858: a non-numeric character was found where a numeric was expected.

I am so confused!!!
0
 
LVL 11

Assisted Solution

by:Ovid Burke
Ovid Burke earned 200 total points
ID: 34944300
On line 23 there appears to be an space at '1 '.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:taviaf
ID: 34944382
Now I get this when I remove the space: Warning: ociexecute() [function.ociexecute]: ORA-01861: literal does not match format string
0
 

Author Comment

by:taviaf
ID: 34944410
So I tried to set my format by doing:
$s = oci_parse($conng, "alter session set nls_date_format='MONTH YYYY'");
oci_execute($s);

Then I get: Warning: ociexecute() [function.ociexecute]: ORA-01843: not a valid month

I don't know which is correct or what to do to fix either one :(
0
 
LVL 11

Expert Comment

by:Ovid Burke
ID: 34944987
Try rewriting the line 23 this way:

order by to_date(T1.months, 'l') desc

Open in new window


0
 
LVL 11

Expert Comment

by:Ovid Burke
ID: 34945027
Hello, I am thinking that the there is still and error in that. So try either of these

order by to_date(T1.months, 'I') desc

Open in new window


or

order by to_date(T1.months, 'Y') desc

Open in new window

0
 

Author Comment

by:taviaf
ID: 34945321
when I do
 order by to_date(T1.months, 'Y') desc
 I get this:  Warning: ociexecute() [function.ociexecute]: ORA-01841: (full) year must be between -4713 and +9999, and not be 0

And when I do
order by to_date(T1.months, 'I') desc
I get this: Warning: ociexecute() [function.ociexecute]: ORA-01820: format code cannot appear in date input format

When I do : order by to_date(T1.months, '1') desc
I get this: Warning: ociexecute() [function.ociexecute]: ORA-01821: date format not recognized

When I do : order by to_date(T1.months, 1) desc
I get this: Warning: ociexecute() [function.ociexecute]: ORA-00932: inconsistent datatypes: expected DATE got NUMBER

Why so many different warnings?!?!?! I don't know what to do...
0
 
LVL 20

Accepted Solution

by:
gatorvip earned 1600 total points
ID: 34945726
>>> order by to_date('1 ' || T1.months) desc ;

The error is here ... T1.months has the format 'MONTH YYYY'  so when you append 1 to it, you'll get something like
to_date( '1 FEBRUARY 2011') and Oracle doesn't know how to read that if your date format is not DD MONTH YYYY.

So you probably want to change the line to read

order by to_date('1 ' || T1.months, 'DD MONTH YYYY') desc ;


Another way would be to use pure dates instead of strings. You can obtain the first of the month with simple SQL: trunc(<date_field>, 'MM')
0
 

Author Closing Comment

by:taviaf
ID: 34946225
I want to thank all of you! It finally works!!!!
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

886 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