简体   繁体   中英

oracle, missing right parenthesis when adding subquery

The inner query is as follow, which works fine independently

select graduate.univid
from graduate, projectmanager, university
where graduate.empid = projectmanager.mgrid and rownum = 1
group by graduate.univid
order by count(graduate.univid) desc;

but when put as subquery, ORACLE sqlplus keep giving "missing right parenthesis" error

select university.univname
from university
where exists 
(
select graduate.univid
from graduate, projectmanager, university
where graduate.empid = projectmanager.mgrid and rownum = 1
group by graduate.univid
order by count(graduate.univid)
);

I have checked similar questions on stackoverflow, but doesn't really help

you use exists so you have to give the condition of university and the subquery. you missed it you get the error i ll guess the right query:

select t1.univname
from university t1
where exists 
(  select 1 from (
   select graduate.univid
   from graduate, projectmanager, university
   where graduate.empid = projectmanager.mgrid and rownum = 1
   group by graduate.univid
   order by count(graduate.univid)) t2 where t2.univid = t1.univid
);

Assuming that rest of your logic is correct, the problem is order by clause. You should use it in subquery. 应该在子查询中使用它。 Try this

select university.univname
from university
where exists 
(
select graduate.univid
from graduate, projectmanager, university
where graduate.empid = projectmanager.mgrid and rownum = 1
group by graduate.univid
);

You can try it out yourself.

This query will return 1

select 1 from dual
where exists
(select 2 as id from dual)

But this will fail and give you ORA-00907: missing right parenthesis

select 1 from dual
where exists
(select 2 as id from dual order by id )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM