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!

Subquery inside CASE statement

b5248923-0d4c-41d9-b30b-902f19b79010Jul 10 2015 — edited Jul 10 2015

I am trying to use a subquery within a Case statement with a 'where' condition that binds to the parent query. Like this:


select 'Tanggal : '||to_char(trxdate,'DD-MON-YYYY hh:mm:ss')||',' as Tgl,

case

  when (select ((a.sk/b.tot)*100)

   from (select count(to_char(response))sk

   from log where response like '%OK%')a,

  (select count(*)tot from log)b)<100

  then

    (select 'Error : '||(to_char(response))||',',count(to_char(response)) je

     from log

     group by to_char(response)

     order by je desc

     )

  else

    (select 'Success Rate : '||substr((a.sukses/b.total)*100,1,5)||' %,'as Success_rate

  from (select count(to_char(response)) sukses from log where response like '%OK%')a, (select count(*) total from log)b)

end as test

from log

where rownum <=1;

But, it issued an error ORA-00907: missing right parenthesis, I try to check the query but didn't find where's error come from ?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 7 2015
Added on Jul 10 2015
8 comments
1,440 views