Skip to Main Content
  • Questions
  • Problem with SQL query getting ORA-00905 in CASE

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Hitesh.

Asked: October 09, 2020 - 12:04 pm UTC

Last updated: October 12, 2020 - 4:38 am UTC

Version: Oracle 11g

Viewed 1000+ times

You Asked

I have a sample table to calculate the customer satisfaction metrics in an organization.

I have created a table as below:

create table nrr_percent
(
wc_id int,
comm_id int,
hmd varchar2);
Table created.

Further, the table looks like this:

WC_ID COMM_ID HMD
---------- ---------- -
1 1 Y
1 2 N
2 3 Y
2 4 N

WC_ID - Work Category ID, COMM_ID - Contact ID, HMD - Metric ( Y-Yes, N- No)

However, when I write the below query:

select wc_id, sum(Y),sum(N) from
( select comm_id,wc_id,
(case when hmd = 'Y' then 1 else 0) as hmd_yes
(case when hmd = 'N' then 1 else 0) as hmd_no
from nrr_percent)
group by wc_id;

Iam getting the error : ORA-00905. Please help and let me know where I went wrong.
Regards
Hitesh

and Connor said...

Case statements must *end*

case when hmd = 'Y' then 1 else 0 end


needs to be

case when hmd = 'Y' then 1 else 0 end




Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library