1. 程式人生 > >oracle in字句裡面不能寫order by的原因

oracle in字句裡面不能寫order by的原因

oracle官網給出了subquery的分類:
A subquery in the FROM clause of a SELECT statement is also called an inline view. A subquery in the WHERE clause of a SELECT statement is also called a nested subquery.
在From 語句中出現的子查詢被稱為 inline view(內聯檢視),在where 語句中出現的子查詢被稱為nested subquery(巢狀子查詢)。


經測試證明在巢狀子查詢中不允許出現order by 語句。例如:
select * from scott.emp
where ename in (select ename from scott.emp order by ename)
會報 “ORA-00907:缺少右括號”的錯誤。


如果將上面的巢狀子查詢再包裝一層,成為第二層查詢的內聯檢視。
select * from scott.emp
where ename in (select * from(select ename from scott.emp order by ename))