Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DECODE & TO_NUMBER Error

453921Jun 16 2009 — edited Jun 16 2009
Hello:

I have a query where I would like to get total counts. The result of the query should look like this:

org clinician name yes no na total
1 123 brown 5 2 0 7
2 345 gray 1 1 1 3
etc....

When I run my query, I receive the following error message:
ORA-01722 - Invalid Number

The sub-query which I'm using to do my counts is based on a field named cmf_flag which is a varchar though it contains a numeric value. Here is the query where I'm going through the decode and to_number process:
select org_key,
           clinician_key, 
           clin_name,
           yes,
           no,
           na,
            total

from 
  
      (select 
         clinician_key, 
	       clin_name, 
         org_key,
        count(decode(to_number(pi.cmf_flag),1,1)) YES,
         count(decode(to_number(pi.cmf_flag),2,1)) NO,
         count(decode(to_number(pi.cmf_flag),3,1)) NA,
         count(pi.rowid) as TOTAL
    
from v_patient_info pi

where org_key = &orgkey
       and program_key = &program_key

group by org_key, clinician_key, clin_name
)

order by org_key asc, clin_name asc;
Can someone help me?

Thanks
This post has been answered by Peter Gjelstrup on Jun 16 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 14 2009
Added on Jun 16 2009
17 comments
1,372 views