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
1,017 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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 50 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 50 total points
ID: 34944300
On line 23 there appears to be an space at '1 '.
0
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now